简体   繁体   English

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

[英]How can I change the background color of a specific column in Kendo grid?

I am using Kendo grid in MVC project. 我在MVC项目中使用Kendo网格。 How can I change the background color of a specific column in Kendo grid? 如何更改Kendo网格中特定列的背景颜色? Grid 格网

@(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);      
        })
    )
)

Here the column "StockSent" should be of different color then other columns. 在此,“ StockSent”列应具有与其他列不同的颜色。

Let's say you want to change the color of the Location column. 假设您要更改“位置”列的颜色。 You add a class to the column, like this: 您将一个类添加到该列,如下所示:

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

Then, in your CSS file, you'll have: 然后,在CSS文件中,您将拥有:

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

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

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