Frozen in React Treegrid component

16 Sep 202314 minutes to read

Frozen rows and columns

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

To use frozen rows and columns support, inject the Freeze module in the tree 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 { ColumnDirective, ColumnsDirective, TreeGridComponent, Freeze, Inject } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { sampleData } from './datasource';
function App() {
    return <TreeGridComponent dataSource={sampleData} childMapping='subtasks' treeColumnIndex={1} height='310' frozenRows={3} frozenColumns={2} allowSelection={false}>
        <ColumnsDirective>
            <ColumnDirective field='taskID' headerText='Task ID' width='120' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='taskName' headerText='Task Name' width='230'></ColumnDirective>
            <ColumnDirective field='startDate' headerText='Start Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='endDate' headerText='End Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='duration' headerText='Duration' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='progress' headerText='Progress' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='priority' headerText='Priority' width='110'></ColumnDirective>
            <ColumnDirective field='approved' headerText='Approved' textAlign='Center' width='110'></ColumnDirective>
            </ColumnsDirective>
            <Inject services={[Freeze]}/>
    </TreeGridComponent>;
}
;
export default App;
import { ColumnDirective, ColumnsDirective, TreeGridComponent, Freeze, Inject } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { sampleData  } from './datasource';

function App() {
    return <TreeGridComponent dataSource={sampleData} childMapping = 'subtasks' treeColumnIndex={1} height='310' frozenRows={3} frozenColumns={2} allowSelection={false}>
        <ColumnsDirective>
            <ColumnDirective field='taskID' headerText='Task ID' width='120' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='taskName' headerText='Task Name' width='230'></ColumnDirective>
            <ColumnDirective field='startDate' headerText='Start Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='endDate' headerText='End Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='duration' headerText='Duration' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='progress' headerText='Progress' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='priority' headerText='Priority' width='110'></ColumnDirective>
            <ColumnDirective field='approved' headerText='Approved' textAlign='Center' width='110'></ColumnDirective>
            </ColumnsDirective>
            <Inject services={[Freeze]} />
    </TreeGridComponent>
};
export default App;

Freeze particular columns

You can use isFrozen property to freeze selected columns in tree grid.

In this demo, the columns with field name taskName and startDate is frozen using the isFrozen property.

import { ColumnDirective, ColumnsDirective, TreeGridComponent, Freeze, Inject } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { sampleData } from './datasource';
function App() {
    return <TreeGridComponent dataSource={sampleData} childMapping='subtasks' height='310' allowSelection={false}>
        <ColumnsDirective>
            <ColumnDirective field='taskID' headerText='Task ID' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='taskName' headerText='Task Name' width='230' isFrozen='true'></ColumnDirective>
            <ColumnDirective field='startDate' headerText='Start Date' width='120' format='yMd' textAlign='Right' isFrozen='true'></ColumnDirective>
            <ColumnDirective field='endDate' headerText='End Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='duration' headerText='Duration' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='progress' headerText='Progress' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='priority' headerText='Priority' width='110'></ColumnDirective>
            <ColumnDirective field='approved' headerText='Approved' textAlign='Center' width='110'></ColumnDirective>
            </ColumnsDirective>
            <Inject services={[Freeze]}/>
    </TreeGridComponent>;
}
;
export default App;
import { ColumnDirective, ColumnsDirective, TreeGridComponent, Freeze, Inject } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { sampleData  } from './datasource';

function App() {
    return <TreeGridComponent dataSource={sampleData} childMapping = 'subtasks' height='310' allowSelection={false} >
        <ColumnsDirective>
            <ColumnDirective field='taskID' headerText='Task ID' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='taskName' headerText='Task Name' width='230' isFrozen='true'></ColumnDirective>
            <ColumnDirective field='startDate' headerText='Start Date' width='120' format='yMd' textAlign='Right' isFrozen='true'></ColumnDirective>
            <ColumnDirective field='endDate' headerText='End Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='duration' headerText='Duration' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='progress' headerText='Progress' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='priority' headerText='Priority' width='110'></ColumnDirective>
            <ColumnDirective field='approved' headerText='Approved' textAlign='Center' width='110'></ColumnDirective>
            </ColumnsDirective>
            <Inject services={[Freeze]} />
    </TreeGridComponent>
};
export default App;

Freeze direction

You can freeze the tree grid columns on the left or right side by using the column.freeze freeze property and the remaining columns will be movable. The tree 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 Task Name column is frozen at the left and the Priority column is frozen at the right side of the content table.

import { ColumnDirective, ColumnsDirective, TreeGridComponent, Freeze, Inject } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { sampleData } from './datasource';
function App() {
    return <TreeGridComponent dataSource={sampleData} childMapping='subtasks' height='310' treeColumnIndex={1} allowSelection={false}>
        <ColumnsDirective>
            <ColumnDirective field='taskID' headerText='Task ID' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='taskName' headerText='Task Name' width='230' freeze='Left'></ColumnDirective>
            <ColumnDirective field='startDate' headerText='Start Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='endDate' headerText='End Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='duration' headerText='Duration' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='progress' headerText='Progress' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='priority' headerText='Priority' width='110' freeze='Right'></ColumnDirective>
            <ColumnDirective field='approved' headerText='Approved' textAlign='Center' width='110'></ColumnDirective>
            </ColumnsDirective>
            <Inject services={[Freeze]}/>
    </TreeGridComponent>;
}
;
export default App;
import { ColumnDirective, ColumnsDirective, TreeGridComponent, Freeze, Inject } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { sampleData  } from './datasource';

function App() {
    return <TreeGridComponent dataSource={sampleData} childMapping = 'subtasks' height='310' treeColumnIndex={1} allowSelection={false} >
        <ColumnsDirective>
            <ColumnDirective field='taskID' headerText='Task ID' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='taskName' headerText='Task Name' width='230' freeze='Left'></ColumnDirective>
            <ColumnDirective field='startDate' headerText='Start Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='endDate' headerText='End Date' width='120' format='yMd' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='duration' headerText='Duration' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='progress' headerText='Progress' width='110' textAlign='Right'></ColumnDirective>
            <ColumnDirective field='priority' headerText='Priority' width='110' freeze='Right'></ColumnDirective>
            <ColumnDirective field='approved' headerText='Approved' textAlign='Center' width='110'></ColumnDirective>
            </ColumnsDirective>
            <Inject services={[Freeze]} />
    </TreeGridComponent>
};
export default App;

Limitations of frozen tree grid

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

  • Row Template
  • Detail Template
  • Cell Editing

Freeze Direction feature has the below limitations, along with the above mentioned limitations.

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

You can refer to our React Tree Grid feature tour page for its groundbreaking feature representations. You can also explore our React Tree Grid example to knows how to present and manipulate data.