Example of Row Hover in ASP.NET Core Data Grid Control
This sample demonstrates the Grid component with the row hover feature. Move the mouse over the Grid rows to see the hover effect.
@* The grid's settings are in the view; the data they read (ViewData) is set in the controller action (see the controller tab). *@
@Html.UiGrid(new UiGridOptions
{
Id = "RowHover",
Data = ViewData["datasource"],
PageCount = 5,
AllowSorting = true,
AllowFiltering = true,
AllowPaging = true,
PageSize = 12,
FilterType = UiGridFilterType.Excel,
EditSettings = new UiEditSettings { AllowAdding = true, AllowEditing = true, AllowDeleting = true },
Toolbar = new List<string> { "Add", "Edit", "Delete", "Update", "Cancel" },
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "ProductID", HeaderText = "Product ID", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, IsPrimaryKey = true, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "ProductName", HeaderText = "Product Name", Width = 150, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "UnitPrice", HeaderText = "Supplier ID", Type = UiColumnType.Number, Width = 130, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "UnitsInStock", HeaderText = "Units In Stock", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "Discontinued", HeaderText = "Discontinued", Type = UiColumnType.Boolean, TextAlign = UiTextAlign.Center, Width = 140, DisplayAsCheckBox = true, EditType = UiEditType.BooleanEdit }
}
})
@Html.UiGrid(new UiGridOptions
{
Id = "RowHover",
Data = ViewData["datasource"],
PageCount = 5,
AllowSorting = true,
AllowFiltering = true,
AllowPaging = true,
PageSize = 12,
FilterType = UiGridFilterType.Excel,
EditSettings = new UiEditSettings { AllowAdding = true, AllowEditing = true, AllowDeleting = true },
Toolbar = new List<string> { "Add", "Edit", "Delete", "Update", "Cancel" },
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "ProductID", HeaderText = "Product ID", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, IsPrimaryKey = true, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "ProductName", HeaderText = "Product Name", Width = 150, ValidationRules = new UiValidationRules { Required = true } },
new UiGridColumn { Field = "UnitPrice", HeaderText = "Supplier ID", Type = UiColumnType.Number, Width = 130, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "UnitsInStock", HeaderText = "Units In Stock", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "Discontinued", HeaderText = "Discontinued", Type = UiColumnType.Boolean, TextAlign = UiTextAlign.Center, Width = 140, DisplayAsCheckBox = true, EditType = UiEditType.BooleanEdit }
}
})
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Lumen.UI.Mvc;
namespace YourApp.Controllers
{
public class GridController : Controller
{
// The page is Views/Grid/RowHover.cshtml; it draws what ViewData holds.
public ActionResult RowHover()
{
var DataSource = Product.GetAllRecords();
ViewData["dataSource"] = DataSource;
return View();
}
}
}
@* Program.cs *@
builder.Services.AddControllersWithViews().AddLumenUIJson();
builder.Services.AddLumenUI();
// ...
app.UseLumenUI();
@* Views/_ViewImports.cshtml *@
@using Lumen.UI.Mvc
@addTagHelper *, Lumen.UI.Core
@* Views/Shared/_Layout.cshtml *@
<head>
@Html.UiStyles()
<link rel="stylesheet" href="~/css/site.css" />
</head>
<body>
@RenderBody()
@Html.UiScripts()
@await RenderSectionAsync("scripts", required: false)
</body>
@* Grids with a DataUrl: @Html.AntiForgeryToken() on the page and [HttpPost, ValidateJsonAntiForgeryToken] on the action. *@
Row Hover feature enables us to identify the current row by highlighting them with the mouse hovers. This can be enabled by setting the EnableHover property as true.
In this demo,by enabling the enableHover property, now you can move the mouse over Grid rows to see the hover effect.