使用默认样式呈现kendo网格行

时间:2014-05-21 00:49:05

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

我的网格是

                      @(Html.Kendo().Grid<student.Models.SearchViewModel>()
    .Name("Grid").HtmlAttributes(new { @class = "studentGrid" })
    .Columns(
                x =>
                {
                    x.Bound(y => y.Id).Hidden(true);
                    x.Bound(y => y.Id).ClientTemplate(@"<input type='checkbox' name='checkedRecords' value='#= Id #' class='mainCheckbox' onclick='checkboxClicked(this, ""checkAllMain"")'/>")
                        .Title("")
                        .HeaderTemplate(@"<input type='checkbox' name='checkAllMain' onclick='selectAll(this, ""mainCheckbox"");' />")
                        .HeaderHtmlAttributes(new { style = "text-align:center" })
                        .Filterable(false)
                        .Sortable(false)
                        .HtmlAttributes(new { @class = "checboxClass", style = "text-align:center" });
                    x.Bound(y => y.abc1).Hidden(false);
                    x.Bound(y => y.abc2).Hidden(false);
                    x.Bound(y => y.abc3).Hidden(false);
                }
    )
        .ToolBar(tb =>
        {
            tb.Custom()
                .Text("Export To Excel")
                .HtmlAttributes(new { id = "export" })
                .Url(Url.Action("Export", Html.CurrentControllerName()));
            tb.Custom()
                .Text("Expand Selected Rows")
                .HtmlAttributes(new { id = "expandSelectedRows" });
        })
        .Groupable()
        .Reorderable(x => x.Columns(true))
        .Pageable(x => x.PageSizes(new int[] { 20, 50, 100 }).Input(true).Numeric(true))
        .Scrollable(x => x.Enabled(true).Height(Model.Height))
        .Resizable(resize => resize.Columns(true))
        .Reorderable(reorder => reorder.Columns(true))
        .Sortable()
        .Selectable()
        .Navigatable()
        .Filterable()
        .ClientDetailTemplateId("subTemplate")
        .AutoBind(!Model.NoAutoload)
                .Events(ev => { ev.DataBound("DataBoundSearch"); })
        .DataSource(dataSource => dataSource
        .Ajax().PageSize(100)
        .ServerOperation(false) // Paging, sorting, filtering and grouping will be done client-side
        .Model(model => model.Id(c => c.Id))
                .Events(events => events.Error("error").RequestStart("RequestStart").RequestEnd("RequestEnd").Change("Changed"))
                .Read(x => x.Action("GetData", Html.CurrentControllerName()).Data("ABCPostData")))       
    )

使用kendo网格时我们选择一行默认情况下用棕色突出显示该行。单击行时无法获取默认颜色。在客户端,它呈现为

       <tr class="k-master-row k-state-selected" data-uid="122bb914-87c2-4f0c-9351-52c1d9b84ae5" style="background-color: rgb(255, 255, 255);">

如何设置为background-color:rgb(255,255,255); ?如何将其覆盖为棕色,如背景颜色:#f0713a,border-color:#f0713a?

1 个答案:

答案 0 :(得分:1)

有几种方法可以做到这一点。最简单的方法是通过CSS

修改所选行的样式

#grid tr.k-state-selected td {
   background-color: #f0713a;
   border-color: #f0713a
}

修改所选单元格的样式

#grid td.k-state-selected {
   background-color: #f0713a;
   border-color: #f0713a
}

并在您的网格声明中确保已设置:

selectable: "cell"

这是单个单元格的demo


另一种方法是使用themebuilder覆盖剑道风格。但这非常笨重。

如果您想以编程方式执行此操作,也可以通过在网格的change事件中获取所选元素,然后在代码中设置元素的背景来实现。如果你需要这个选项,我会尝试这样做,但是我看到它的方式,将UI的东西留给css,并将编码留给javascript。

相关问题