简体   繁体   English

如何使用行索引更改剑道网格行的背景颜色

[英]how to change background color of kendo grids row using the row index

i need to change the color of kendo grids row by using it's index no. 我需要使用索引号更改剑道网格行的颜色。 i tried using this but nothing happened. 我尝试使用它,但没有任何反应。

       var gview = $('#SearchResult').data().kendoGrid;//searchresult is grid's id
        var dataRows = gview.items();
        var rowIndex = dataRows.index(gview.select());
         gview.tbody.find("tr:eq("+rowIndex+")").css("background-color", "green");

It's not throwing any error in debugger but not giving any result. 它不会在调试器中引发任何错误,但不会给出任何结果。

You need to find Uid of a row by its index and find tr by its data-uid, check below function 您需要通过其索引找到行的Uid,并通过其数据uid找到tr,请检查以下功能

function ChangeGridRowByIndex(index) {
    var grid = $("#SearchResult").data("kendoGrid");
    var gridData = grid.dataSource.view();
    var currentUid = gridData[index].uid;
    var currenRow = grid.table.find("tr[data-uid='" + currentUid + "']");
    $(currenRow).addClass("red");
}

Hope this will help you :) 希望这个能对您有所帮助 :)

Given that kendo does not give an option to control the background color of a single row directly (that I know of). 鉴于kendo没有提供直接控制单行背景颜色的选项(据我所知)。 But you must apply the new color after the table is rendered and you might also need to apply it after every refresh of the table also (kendo should have events thrown for this). 但是,您必须在呈现表格后应用新颜色,并且还可能在每次刷新表格后也应用新颜色(kendo应该为此抛出事件)。 Once kendo finshes painting it, grab the table element in your page, by default kendo gives it a class="k-grid-content". 一旦kendo画完了它,就抓住页面中的table元素,默认情况下kendo给它一个class =“ k-grid-content”。 Using jquery it would look something like this 使用jQuery,它看起来像这样

var differentRowElement = $('.k-grid-content').find('tr').eq(index).css('background-color', 'red');

Tested it on http://demos.telerik.com/kendo-ui/grid/index running this in the console http://demos.telerik.com/kendo-ui/grid/index上对其进行了测试,并在控制台中运行

$('.k-grid-content').find('tr').eq(3).css('background-color', 'red');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM