Rows
Control the appearance of Grid rows by getting rows by model ID, adding custom rows, using row templates, and disabling the hover effect.
Getting Rows by Model ID
To get a table row in the Grid by the ID of the data item:
- Make sure the Id field is defined in the model configuration of the data source of the Grid.
- Retrieve the data item, read its UID, and then select the corresponding table row.
var grid = $("#grid").data("kendoGrid"); // Get the Grid instance.
var dataItem = grid.dataSource.get(10249); // The get() method of the dataSource only works when the model id is set.
var tableRow = $("[data-uid='" + dataItem.uid + "']"); // Get the row by its unique data-uid attribute. This UID is rendered by the Grid automatically.
Adding Custom Rows
You can manually add a table row with a user-friendly message when the DataSource returns no data, for example, after filtering. For more information, see Row Templates in the Grid HtmlHelper for ASP.NET Core.
The following example demonstrates how to add a table row in the DataBound() event handler of the Grid.
@(Html.Kendo().Grid<AspNetCoreGrid.Models.OrderViewModel>()
.Name("grid")
.Filterable()
/* Other configuration. */
.Events(e=>e.DataBound("onGridDataBound"))
)Using Row Templates
Use row templates to customize row markup and content. For implementation details, see Row Templates in the Grid HtmlHelper for ASP.NET Core.
Disabling the Hover Effect
Hover is a UI state that improves row visibility, especially across long rows and while editing. If your project must avoid the hover state, use one of the following approaches:
-
Open the Kendo UI theme CSS file (for example,
kendo.default.min.css) and remove this CSS rule.CSS.k-grid tr:hover { /* ...background styles here... */ } -
Override the
hoverstyling by using the CSS from the following example. The#f1f1f1value corresponds to the background color of the.k-alttable rows. To find the correct value for your Kendo UI theme, use the browser DOM inspector, or set a background color of your preference.CSS.k-grid tr:not(.k-selected):hover { background: none; color: inherit; } .k-grid tr.k-alt:not(.k-selected):hover { background: #f1f1f1; }