如何更改Kendo网格中特定列的背景颜色?

时间:2015-03-20 16:03:35

标签: jquery asp.net-mvc kendo-grid

我在MVC项目中使用Kendo网格。如何更改Kendo网格中特定列的背景颜色? 格

@(Html.Kendo().Grid<Webapplication1.Models.mainViewModel>()
    .Name("mainGrid")
    .Columns(c =>
    {
        c.Bound(m => m.Id).Hidden();
        c.Bound(m => m.CountryViewModel.CountryName)
            .Title("Country").HeaderHtmlAttributes(new { @title = "Countries" });
        c.Bound(m => m.LocationViewModel.LocationName)
            .Title("Location").HeaderHtmlAttributes(new { @title = "Locations" });
        c.Bound(m => m.StockSent)
            .Title("StockSent");
        c.Command(p =>
        {p.Edit().Text(" ").UpdateText(" ").CancelText(" ").HtmlAttributes(new { @title = "Edit" });});
    })
    .ToolBar(toolbar => { toolbar.Create().Text("").HtmlAttributes(new { @title = "Add"}); })
    .Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.PopUp).TemplateName("gridEditor"))
    .DataSource(dataSource => dataSource
.Ajax()
        .PageSize(10)
        .Read(read => read.Action("mainGrid_Read", "abc"))
    .Update(update => update.Action("mainGrid_Update", "abc"))
    .Create(create => create.Action("mainGrid_Create", "abc"))
        .Model(m => { m.Id(p => p.Id);
          m.Field(p => p.CountryViewModel).DefaultValue(ViewData["DefaultCountry"] as Webapplication1.Models.CountryViewModel);      
        })
    )
)

这里的列&#34; StockSent&#34;应该是与其他列不同的颜色。

1 个答案:

答案 0 :(得分:2)

假设您要更改“位置”列的颜色。您可以向列中添加一个类,如下所示:

c.Bound(m => m.LocationViewModel.LocationName)
            .Title("Location")
            .HeaderHtmlAttributes(new { @title = "Locations" })
            .HtmlAttributes(new { @class = "colored-col" });

然后,在您的CSS文件中,您将拥有:

.colored-col { background-color: #ff0000 }