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.
To use frozen rows and columns support, inject the Freeze
module in the grid.
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.
import { Grid, Freeze, Selection } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject(Freeze, Selection);
let grid: Grid = new Grid({
dataSource: data,
height: 315,
allowSelection: false,
enableHover: false,
frozenRows: 3,
frozenColumns: 2,
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120 },
{ field: 'CustomerID', headerText: 'Customer ID', width: 150 },
{ field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'Right' },
{ field: 'EmployeeID', headerText: 'Employee ID', textAlign: 'Right', width: 120 },
{ field: 'ShipName', headerText: 'Ship Name', width: 150 },
{ field: 'ShipAddress', headerText: 'Ship Address', width: 170 },
{ field: 'ShipCity', headerText: 'Ship City', width: 150 },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 150 },
{ field: 'ShipRegion', headerText: 'Ship Region', width: 150 },
{ field: 'ShipPostalCode', headerText: 'Ship Postal Code', width: 150 },
{ field: 'Freight', headerText: 'Freight', width: 120 }
]
});
grid.appendTo('#Grid');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Grid</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Grid Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-grids/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-calendars/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style='height:350px;'>
<div id='Grid'></div>
</div>
</body>
</html>
- 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.
The following features are not supported in frozen rows and columns:
You can use isFrozen
property to freeze selected columns in grid.
In this demo, the columns with field name OrderID
and EmployeeID
is frozen using
the isFrozen
property.
import { Grid, Freeze, Selection } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject(Freeze, Selection);
let grid: Grid = new Grid({
dataSource: data,
height: 315,
allowSelection: false,
enableHover: false,
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120, isFrozen: true },
{ field: 'CustomerID', headerText: 'Customer ID', width: 150 },
{ field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'Right' },
{ field: 'EmployeeID', headerText: 'Employee ID', textAlign: 'Right', width: 120, isFrozen: true },
{ field: 'ShipName', headerText: 'Ship Name', width: 150 },
{ field: 'ShipAddress', headerText: 'Ship Address', width: 170 },
{ field: 'ShipCity', headerText: 'Ship City', width: 150 },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 150 },
{ field: 'ShipRegion', headerText: 'Ship Region', width: 150 },
{ field: 'ShipPostalCode', headerText: 'Ship Postal Code', width: 150 },
{ field: 'Freight', headerText: 'Freight', width: 120 }
]
});
grid.appendTo('#Grid');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Grid</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Grid Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-grids/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-calendars/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style='height:350px;'>
<div id='Grid'></div>
</div>
</body>
</html>
isFrozen
is not compatible with the Freeze direction feature.
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.
import { Grid, Freeze } from '@syncfusion/ej2-grids';
import { data } from './datasource.ts';
Grid.Inject(Freeze);
let grid: Grid = new Grid({
dataSource: data,
height: 315,
enableHover: false,
frozenRows: 2,
columns: [
{ field: 'OrderID', headerText: 'Order ID', textAlign: 'Right', width: 120 },
{ field: 'Freight', headerText: 'Freight', format: 'C2', width: 120 }
{ field: 'CustomerID', headerText: 'Customer ID', width: 150, freeze: 'Right' },
{ field: 'OrderDate', headerText: 'Order Date', width: 130, format: 'yMd', textAlign: 'Right' },
{ field: 'ShipName', headerText: 'Ship Name', width: 150 },
{ field: 'ShipAddress', headerText: 'Ship Address', width: 170 },
{ field: 'ShipCity', headerText: 'Ship City', width: 150 },
{ field: 'ShipCountry', headerText: 'Ship Country', width: 150, freeze: 'Left' }
]
});
grid.appendTo('#Grid');
<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 Grid</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript Grid Control" />
<meta name="author" content="Syncfusion" />
<link href="index.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-grids/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-calendars/styles/material.css" rel="stylesheet" />
<link href="//cdn.syncfusion.com/ej2/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="systemjs.config.js"></script>
</head>
<body>
<div id='loader'>Loading....</div>
<div id='container' style='height:350px;'>
<div id='Grid'></div>
</div>
</body>
</html>
- Freeze Direction is not compatible with the
isFrozen
andfrozenColumns
properties.
This feature has the below limitations, along with the above mentioned Frozen Grid limitations.