Example of Row Height in ASP.NET Core Data Grid Control
This sample demonstrates the row height feature of the Grid. In this demo, the RowHeight for all the Grid rows can be changed as 20px, 40px and 60px on ToolBar button click.
@Html.UiGrid(new UiGridOptions
{
Id = "RowHeight",
OnToolbarClick = "toolbarClick",
ToolbarItems = new List<UiGridToolbarItem>
{
new UiGridToolbarItem { Id = "big", Text = "Small", TooltipText = "Row-height-big", Align = UiToolbarAlign.Right },
new UiGridToolbarItem { Id = "medium", Text = "Medium", TooltipText = "Row-height-medium", Align = UiToolbarAlign.Right },
new UiGridToolbarItem { Id = "small", Text = "Large", TooltipText = "Row-height-small", Align = UiToolbarAlign.Right }
},
Data = ViewData["dataSource"],
RowHeight = 20,
Height = "400px",
AllowSorting = true,
AllowFiltering = true,
FilterType = UiGridFilterType.Excel,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "OrderID", HeaderText = "Order ID", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "CustomerID", HeaderText = "Customer Name", Width = 150, ShowInColumnChooser = false },
new UiGridColumn { Field = "OrderDate", HeaderText = "Order Date", Type = UiColumnType.Date, Width = 130, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy" },
new UiGridColumn { Field = "Freight", HeaderText = "Freight", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, Format = "C2" },
new UiGridColumn { Field = "ShippedDate", HeaderText = "Shipped Date", Type = UiColumnType.Date, Width = 140, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy" },
new UiGridColumn { Field = "ShipCity", Visible = false, HeaderText = "Ship Country", Width = 150 },
new UiGridColumn { Field = "ShipCountry", Visible = false, HeaderText = "Ship Country", Width = 150 }
}
})
@Html.UiGrid(new UiGridOptions
{
Id = "RowHeight",
OnToolbarClick = "toolbarClick",
ToolbarItems = new List<UiGridToolbarItem>
{
new UiGridToolbarItem { Id = "big", Text = "Small", TooltipText = "Row-height-big", Align = UiToolbarAlign.Right },
new UiGridToolbarItem { Id = "medium", Text = "Medium", TooltipText = "Row-height-medium", Align = UiToolbarAlign.Right },
new UiGridToolbarItem { Id = "small", Text = "Large", TooltipText = "Row-height-small", Align = UiToolbarAlign.Right }
},
Data = ViewData["dataSource"],
RowHeight = 20,
Height = "400px",
AllowSorting = true,
AllowFiltering = true,
FilterType = UiGridFilterType.Excel,
Columns = new List<UiGridColumn>
{
new UiGridColumn { Field = "OrderID", HeaderText = "Order ID", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right },
new UiGridColumn { Field = "CustomerID", HeaderText = "Customer Name", Width = 150, ShowInColumnChooser = false },
new UiGridColumn { Field = "OrderDate", HeaderText = "Order Date", Type = UiColumnType.Date, Width = 130, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy" },
new UiGridColumn { Field = "Freight", HeaderText = "Freight", Type = UiColumnType.Number, Width = 120, TextAlign = UiTextAlign.Right, Format = "C2" },
new UiGridColumn { Field = "ShippedDate", HeaderText = "Shipped Date", Type = UiColumnType.Date, Width = 140, TextAlign = UiTextAlign.Right, Format = "M/d/yyyy" },
new UiGridColumn { Field = "ShipCity", Visible = false, HeaderText = "Ship Country", Width = 150 },
new UiGridColumn { Field = "ShipCountry", Visible = false, HeaderText = "Ship Country", Width = 150 }
}
})
<script>
// The row height Syncfusion's three buttons set: 20, 40 and 60 pixels.
function toolbarClick(args) {
var heights = { big: 20, medium: 40, small: 60 };
if (heights[args.item.id]) { window.Lumen.get('RowHeight').setRowHeight(heights[args.item.id]); }
}
</script>
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/RowHeight.cshtml; it draws what ViewData holds.
public ActionResult RowHeight()
{
var order = OrdersDetails.GetAllRecords();
ViewData["datasource"] = order;
return View();
}
/// <summary>One order: the rows of Syncfusion's Grid samples that use the orders.</summary>
public class OrdersDetails
{
public OrdersDetails()
{
}
public OrdersDetails(int OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified, DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry, DateTime ShippedDate, string ShipAddress)
{
this.OrderID = OrderID;
this.CustomerID = CustomerId;
this.EmployeeID = EmployeeId;
this.Freight = Freight;
this.ShipCity = ShipCity;
this.Verified = Verified;
this.OrderDate = OrderDate;
this.ShipName = ShipName;
this.ShipCountry = ShipCountry;
this.ShippedDate = ShippedDate;
this.ShipAddress = ShipAddress;
}
public int OrderID { get; set; }
public string CustomerID { get; set; }
public int EmployeeID { get; set; }
public double Freight { get; set; }
public string ShipCity { get; set; }
public bool Verified { get; set; }
public DateTime OrderDate { get; set; }
public string ShipName { get; set; }
public string ShipCountry { get; set; }
public DateTime ShippedDate { get; set; }
public string ShipAddress { get; set; }
public static List<OrdersDetails> GetAllRecords()
{
List<OrdersDetails> order = new List<OrdersDetails>();
int code = 10000;
for (int i = 1; i < 10; i++)
{
order.Add(new OrdersDetails(code + 1, "ALFKI", i + 0, 2.3 * i, false, new DateTime(1991, 05, 15, 10, 40, 00), "Berlin", "Simons bistro", "Denmark", new DateTime(1996, 7, 16, 09, 30, 00), "Kirchgasse 6"));
order.Add(new OrdersDetails(code + 2, "ANATR", i + 2, 3.3 * i, true, new DateTime(1990, 04, 04, 09, 30, 00), "Madrid", "Queen Cozinha", "Brazil", new DateTime(1996, 9, 11, 03, 45, 00), "Avda. Azteca 123"));
order.Add(new OrdersDetails(code + 3, "ANTON", i + 1, 4.3 * i, true, new DateTime(1957, 11, 30, 03, 45, 00), "Cholchester", "Frankenversand", "Germany", new DateTime(1996, 10, 7, 07, 50, 00), "Carrera 52 con Ave. Bolívar #65-98 Llano Largo"));
order.Add(new OrdersDetails(code + 4, "BLONP", i + 3, 5.3 * i, false, new DateTime(1930, 10, 22, 07, 30, 00), "Marseille", "Ernst Handel", "Austria", new DateTime(1996, 12, 30, 06, 12, 00), "Magazinweg 7"));
order.Add(new OrdersDetails(code + 5, "BOLID", i + 4, 6.3 * i, true, new DateTime(1953, 02, 18, 05, 50, 00), "Tsawassen", "Hanari Carnes", "Switzerland", new DateTime(1997, 12, 3, 12, 50, 00), "1029 - 12th Ave. S."));
code += 5;
}
return order;
}
}
}
}
@* 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. *@
The Grid has support to provide RowHeight property.