- InitialBlocks
- Cache Mode
- Limitations for Infinite Scrolling
Contact Support
Infinite scroll in React Treegrid component
3 Dec 202413 minutes to read
Infinite scrolling is used to load a huge amount of data without degrading the Tree Grid performance. This feature works like the lazy loading concept, which means the buffer data is loaded only when the scrollbar reaches the end of the scroller.
To enable Infinite scrolling, set enableInfiniteScrolling
property as true and inject InfiniteScroll module in Tree Grid.
- In this feature, Tree Grid will not make a new data request when you visit the same page again.
import { TreeGridComponent, ColumnsDirective, ColumnDirective, Inject, InfiniteScroll } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { dataSource, virtualData } from './datasource';
function App() {
dataSource();
return <TreeGridComponent dataSource={virtualData} childMapping='Crew' enableInfiniteScrolling={true} treeColumnIndex={1} height='291'>
<ColumnsDirective>
<ColumnDirective field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD1' headerText='Player Name' width='120'></ColumnDirective>
<ColumnDirective field='FIELD2' headerText='Year' width='100' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD3' headerText='Stint' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD4' headerText='TMID' width='120' textAlign='Right'></ColumnDirective>
</ColumnsDirective>
<Inject services={[InfiniteScroll]}/>
</TreeGridComponent>;
}
;
export default App;
import { TreeGridComponent, ColumnsDirective, ColumnDirective, Inject, InfiniteScroll } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { dataSource, virtualData } from './datasource';
function App() {
dataSource();
return <TreeGridComponent dataSource={virtualData} childMapping = 'Crew' enableInfiniteScrolling={true} treeColumnIndex={1} height='291'>
<ColumnsDirective>
<ColumnDirective field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD1' headerText='Player Name' width='120'></ColumnDirective>
<ColumnDirective field='FIELD2' headerText='Year' width='100' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD3' headerText='Stint' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD4' headerText='TMID' width='120' textAlign='Right'></ColumnDirective>
</ColumnsDirective>
<Inject services={[InfiniteScroll]} />
</TreeGridComponent>
};
export default App;
InitialBlocks
You can define the initial loading pages count by using infiniteScrollSettings.initialBlocks
property. By default, this feature loads three pages in initial rendering.
In the below demo, we have changed this property value to load five page records instead of three.
import { TreeGridComponent, ColumnsDirective, ColumnDirective, Inject, InfiniteScroll } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { dataSource, virtualData } from './datasource';
function App() {
const pageSettings = { pageSize: 50 };
const infiniteOptions = { initialBlocks: 5 };
dataSource();
return <TreeGridComponent dataSource={virtualData} childMapping='Crew' height={300} enableInfiniteScrolling={true} infiniteScrollSettings={infiniteOptions} pageSettings={pageSettings} treeColumnIndex={1}>
<Inject services={[InfiniteScroll]}/>
<ColumnsDirective>
<ColumnDirective field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD1' headerText='Player Name' width='120'></ColumnDirective>
<ColumnDirective field='FIELD2' headerText='Year' width='100' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD3' headerText='Stint' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD4' headerText='TMID' width='120' textAlign='Right'></ColumnDirective>
</ColumnsDirective>
</TreeGridComponent>;
}
;
export default App;
import { TreeGridComponent, ColumnsDirective, ColumnDirective, Inject, InfiniteScroll, InfiniteScrollSettingsModel, PageSettingsModel } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { dataSource, virtualData } from './datasource';
function App() {
const pageSettings: PageSettingsModel = { pageSize: 50 };
const infiniteOptions: InfiniteScrollSettingsModel = { initialBlocks: 5 };
dataSource();
return <TreeGridComponent dataSource={virtualData} childMapping = 'Crew' height={300} enableInfiniteScrolling={true} infiniteScrollSettings={ infiniteOptions } pageSettings={ pageSettings } treeColumnIndex={1}>
<Inject services={[InfiniteScroll]} />
<ColumnsDirective>
<ColumnDirective field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD1' headerText='Player Name' width='120'></ColumnDirective>
<ColumnDirective field='FIELD2' headerText='Year' width='100' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD3' headerText='Stint' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD4' headerText='TMID' width='120' textAlign='Right'></ColumnDirective>
</ColumnsDirective>
</TreeGridComponent>
};
export default App;
Cache Mode
Cache is used to store the loaded rows object in the Tree Grid instance which can be reused for creating the row elements whenever you scroll to already visited page. Also, this mode maintains row elements based on the infiniteScrollSettings.maxBlocks
count value, once this limit exceeds then it will remove row elements from DOM for new rows.
To enable the cache mode in Infinite scrolling, set infiniteScrollSettings.enableCache
property as true.
import { TreeGridComponent, ColumnsDirective, ColumnDirective, Inject, InfiniteScroll } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { dataSource, virtualData } from './datasource';
function App() {
const pageSettings = { pageSize: 50 };
const infiniteOptions = { enableCache: true };
dataSource();
return <TreeGridComponent dataSource={virtualData} childMapping='Crew' height={300} enableInfiniteScrolling={true} infiniteScrollSettings={infiniteOptions} pageSettings={pageSettings} treeColumnIndex={1}>
<Inject services={[InfiniteScroll]}/>
<ColumnsDirective>
<ColumnDirective field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD1' headerText='Player Name' width='120'></ColumnDirective>
<ColumnDirective field='FIELD2' headerText='Year' width='100' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD3' headerText='Stint' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD4' headerText='TMID' width='120' textAlign='Right'></ColumnDirective>
</ColumnsDirective>
</TreeGridComponent>;
}
;
export default App;
import { TreeGridComponent, ColumnsDirective, ColumnDirective, Inject, InfiniteScroll, InfiniteScrollSettingsModel, PageSettingsModel } from '@syncfusion/ej2-react-treegrid';
import * as React from 'react';
import { dataSource, virtualData } from './datasource';
function App() {
const pageSettings: PageSettingsModel = { pageSize: 50 };
const infiniteOptions: InfiniteScrollSettingsModel = { enableCache: true };
dataSource();
return <TreeGridComponent dataSource={virtualData} childMapping = 'Crew' height={300} enableInfiniteScrolling={true} infiniteScrollSettings={ infiniteOptions } pageSettings={ pageSettings } treeColumnIndex={1}>
<Inject services={[InfiniteScroll]} />
<ColumnsDirective>
<ColumnDirective field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD1' headerText='Player Name' width='120'></ColumnDirective>
<ColumnDirective field='FIELD2' headerText='Year' width='100' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD3' headerText='Stint' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='FIELD4' headerText='TMID' width='120' textAlign='Right'></ColumnDirective>
</ColumnsDirective>
</TreeGridComponent>
};
export default App;
Limitations for Infinite Scrolling
- Due to the element height limitation in browsers, the maximum number of records loaded by the tree grid is limited due to the browser capability.
- Initial loading rows total height must be greater than the viewport height.
- Cell selection will not be persisted in cache mode.
- Infinite scrolling is not compatible with batch editing, cell editing, detail template.
- The aggregated information and total group items are displayed based on the current view items. To get these information regardless of the view items, refer to the
- Programmatic selection using the
selectRows
andselectRow
method is not supported in infinite scrolling. - Infinite scrolling does not support rendering records in a collapsed state. All records must be fully expanded at initial rendering for proper functionality.
You can refer to our
React Tree Grid
feature tour page for its groundbreaking feature representations. You can also explore ourReact Tree Grid example
to knows how to present and manipulate data.