Search results

Frozen Rows and Columns in ASP.NET Core Grid control

02 Aug 2021 / 2 minutes to read

Frozen rows and columns provides an option to make rows and columns always visible in the top and left side of the grid while scrolling.

In this demo, the frozenColumns is set as ‘2’ and the frozenRows is set as ‘3’. Hence, the left two columns and top three rows are frozen.

tagHelper
freeze-row-column.cs
Copied to clipboard
<ejs-grid id="Grid" dataSource="ViewBag.datasource" height="315" allowSelection="false" enableHover="false" frozenColumns="2" frozenRows="3" width="100%" > 
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120" ></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
        <e-grid-column field="EmployeeID" headerText=" Employee ID" textAlign="Right"  width="120"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>        
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipAddress" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
        <e-grid-column field="ShipRegion" headerText="Ship Region" width="150"></e-grid-column>
        <e-grid-column field="ShipPostalCode" headerText="Ship Postal Code" width="150"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="120"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
Copied to clipboard
public IActionResult Index()
 {
    ViewBag.datasource = OrdersDetails.GetAllRecords();            
    return View();
 }

Frozen rows and columns should not be set outside the grid view port. Frozen Grid will support row and column virtualization feature, which helps to improve the Grid performance while loading a large dataset.

Limitations of Frozen Grid

The following features are not supported in frozen rows and columns:

  • Grouping
  • Row Template
  • Detail Template
  • Hierarchy Grid

Freeze particular columns

To freeze particular column in the grid, the isFrozen property of e-grid-column tag helper can be used.

In this demo, the columns with field name OrderID and EmployeeID is frozen using the isFrozen property of e-grid-column.

tagHelper
freeze-column.cs
Copied to clipboard
<ejs-grid id="Grid" dataSource="ViewBag.datasource" height="315" allowSelection="false" enableHover="false" frozenColumns="2" frozenRows="3" width="100%" > 
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120" isFrozen="true"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer Name" width="150"></e-grid-column>
        <e-grid-column field="EmployeeID" headerText=" Employee ID" textAlign="Right" isFrozen="true" width="120"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>        
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipAddress" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150"></e-grid-column>
        <e-grid-column field="ShipRegion" headerText="Ship Region" width="150"></e-grid-column>
        <e-grid-column field="ShipPostalCode" headerText="Ship Postal Code" width="150"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="120"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
Copied to clipboard
public IActionResult Index()
 {
    var orders = OrderDetails.GetAllRecords();
    ViewBag.datasource = orders;            
    return View();
  }
  • isFrozen is not compatible with the Freeze direction feature.

Freeze Direction

You can freeze the Grid columns on the left or right side by using the column.freeze property and the remaining columns will be movable. The grid will automatically move the columns to the left or right position based on the column.freeze value.

Types of the column.freeze directions:

  • Left: Allows you to freeze the columns at the left.
  • Right: Allows you to freeze the columns at the right.

In this demo, the ShipCountry column is frozen at the left and the CustomerID column is frozen at the right side of the content table.

tagHelper
Copied to clipboard
<ejs-grid id="Grid" dataSource="ViewBag.datasource" height="315" enableHover="false" frozenRows="2">
    <e-grid-columns>
        <e-grid-column field="OrderID" headerText="Order ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" width="120"></e-grid-column>
        <e-grid-column field="CustomerID" headerText="Customer ID" width="150" freeze="Right"></e-grid-column>
        <e-grid-column field="EmployeeID" headerText=" Employee ID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="OrderDate" headerText=" Order Date" textAlign="Right" format="yMd" width="130"></e-grid-column>
        <e-grid-column field="ShipName" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipAddress" headerText="Ship Name" width="150"></e-grid-column>
        <e-grid-column field="ShipCity" headerText="Ship City" width="150"></e-grid-column>
        <e-grid-column field="ShipCountry" headerText="Ship Country" width="150" freeze="Left"></e-grid-column>
    </e-grid-columns>
</ejs-grid>
  • Freeze Direction is not compatible with the isFrozen and frozenColumns properties.

Limitations of Freeze Direction

This feature has the below limitations, along with the above mentioned Frozen Grid limitations.

  • Column virtualization
  • Infinite scroll cache mode
  • Freeze direction in the stacked header is not compatible with column reordering.