【问题标题】:Kendo UI Grid cell coloring in MVC4MVC4中的Kendo UI网格单元格着色
【发布时间】:2014-07-25 12:04:12
【问题描述】:

在剑道 UI 网格中。我想更改单元格的背景,其值为 -111, -222 和 IV , IT。

帮我写 jquery 来改变背景颜色。

我的代码:

    @(Html.Kendo().Grid(Model)
    .Name("gridexcel")
    .Events(events => events.DataBound(@<text>coloring()</text>))
    .Columns(columns =>
    {
     columns.Bound(c => c.ExcelId).Title("Id").Visible(false);
     columns.Bound(c => c.status).Title("Status").Width(100);
     columns.Bound(c => c.report_date).Title("Report Date");
     columns.Bound(c => c.code).Width(50);
 //and additional columns from 1 to 50
    }


    var coloring = function () {
    var grid = $("#gridexcel").data("kendoGrid");

    grid.tbody
    .find(":contains('-111')")
    .closest("td")
    .css("background", "red");
    grid.tbody
    .find(":contains('-222')")
    .closest("tr")
    .css("background", "red");

    grid.tbody
    .find(":contains('IV')")
    .closest("tr")
    .css("background", "green");

    grid.tbody
    .find(":contains('IT')")
    .closest("tr")
    .css("background", "red");
    }; 

【问题讨论】:

  • 您希望更改哪一列的背景色?

标签: javascript asp.net-mvc-4 kendo-ui kendo-grid kendo-asp.net-mvc


【解决方案1】:

你只需要添加如下单行代码,而不是选择所有值:

$('td').each(function(){if($(this).text()=='-111'){$(this).addClass('red')}});    

请查看工作演示:
Kendo Grid Changing Cell Color

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-01
    相关资源
    最近更新 更多