Grid allows you to load large amount of data without performance degradation.
To use virtualization, you need to inject VirtualScroll module in grid.
Row virtualization allows you to load and render rows only in content viewport.
It is an alternative way of paging in which the data will load while scrolling vertically.
To setup the row virtualization, you need to define
enableVirtualization
as true and
content height by height
property.
The number of records displayed in the Grid is determined implicitly by height of content area. Also you have an option to define visible number of records by pageSettings.pageSize
property.
The loaded data will be cached and reused when it is needed for next time.
import { ColumnDirective, ColumnsDirective, GridComponent, Inject } from '@syncfusion/ej2-react-grids';
import { PageSettingsModel, VirtualScroll} from '@syncfusion/ej2-react-grids';
import * as React from 'react';
import { data } from './largeData';
export default class App extends React.Component<{}, {}>{
public data: object[] = data(1000);
public pageSettings: PageSettingsModel = { pageSize: 50 };
public render() {
return <GridComponent dataSource={this.data} height={300} enableVirtualization={true}
pageSettings={ this.pageSettings }>
<Inject services={[VirtualScroll]} />
<ColumnsDirective>
<ColumnDirective field='TaskID' headerText='Task ID' width='70' textAlign='Right'/>
<ColumnDirective field='Engineer' width='100'/>
<ColumnDirective field='Designation' width='100'/>
<ColumnDirective field='Estimation' headerText='Estimation' textAlign='Right' width='100'/>
<ColumnDirective field='Status' width='100'/>
</ColumnsDirective>
</GridComponent>
}
}
const names = ['TOM', 'Hawk', 'Jon', 'Chandler', 'Monica', 'Rachel', 'Phoebe', 'Gunther', 'Ross',
'Geller', 'Joey', 'Bing', 'Tribbiani', 'Janice', 'Bong', 'Perk', 'Green',
'Ken', 'Adams'];
const hours = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const designation = ['Manager', 'Engineer 1', 'Engineer 2', 'Developer', 'Tester'];
const status = ['Completed', 'Open', 'In Progress', 'Review', 'Testing']
export function data(count: number) {
const result = [];
for (let i = 0; i < count; i++) {
result.push({
Designation: designation[Math.round(Math.random() * designation.length)] || designation[0],
Engineer: names[Math.round(Math.random() * names.length)] || names[0],
Estimation: hours[Math.round(Math.random() * hours.length)] || hours[0],
Status: status[Math.round(Math.random() * status.length)] || status[0],
TaskID: i + 1
});
}
return result;
};
Column virtualization allows you to virtualize columns. It will render columns which are in viewport. You can scroll horizontally to view more columns.
To setup the column virtualization, set the enableVirtualization
and enableColumnVirtualization
properties as true.
import { ColumnDirective, ColumnsDirective, GridComponent } from '@syncfusion/ej2-react-grids';
import { Inject, VirtualScroll} from '@syncfusion/ej2-react-grids';
import * as React from 'react';
import { dataSource } from './virtualData';
export default class App extends React.Component<{}, {}>{
public data: object[] = dataSource();
public render() {
return <GridComponent dataSource={this.data} height={300} enableVirtualization={true}
enableColumnVirtualization={true} pageSettings={{ pageSize: 50 }}>
<Inject services={[VirtualScroll]} />
<ColumnsDirective>
<ColumnDirective field='FIELD1' headerText='Player Name' width='140'/>
<ColumnDirective field='FIELD2' headerText='Year' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD3' headerText='Stint' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD4' headerText='TMID' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD5' headerText='LGID' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD6' headerText='GP' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD7' headerText='GS' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD8' headerText='Minutes' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD9' headerText='Points' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD10' headerText='oRebounds' width='130' textAlign='Right'/>
<ColumnDirective field='FIELD11' headerText='dRebounds' width='130' textAlign='Right'/>
<ColumnDirective field='FIELD12' headerText='Rebounds' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD13' headerText='Assists' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD14' headerText='Steals' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD15' headerText='Blocks' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD16' headerText='Turnovers' width='130' textAlign='Right'/>
<ColumnDirective field='FIELD17' headerText='PF' width='130' textAlign='Right'/>
<ColumnDirective field='FIELD18' headerText='fgAttempted' width='150' textAlign='Right'/>
<ColumnDirective field='FIELD19' headerText='fgMade' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD20' headerText='ftAttempted' width='150' textAlign='Right'/>
<ColumnDirective field='FIELD21' headerText='ftMade' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD22' headerText='ThreeAttempted' width='150' textAlign='Right'/>
<ColumnDirective field='FIELD23' headerText='ThreeMade' width='130' textAlign='Right'/>
<ColumnDirective field='FIELD24' headerText='PostGP' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD25' headerText='PostGS' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD26' headerText='PostMinutes' width='120' textAlign='Right'/>
<ColumnDirective field='FIELD27' headerText='PostPoints' width='130' textAlign='Right'/>
<ColumnDirective field='FIELD28' headerText='PostoRebounds' width='130' textAlign='Right'/>
<ColumnDirective field='FIELD29' headerText='PostdRebounds' width='130' textAlign='Right'/>
<ColumnDirective field='FIELD30' headerText='PostRebounds' width='130' textAlign='Right'/>
</ColumnsDirective>
</GridComponent>
}
};
Column’s
width
is required for column virtualization. If column’s width is not defined then Grid will consider its value as 200px.
Both the row and column virtualization can be used along with grouping. At initial rendering, the virtual height of scrollbar will be set based on the total number of records and after grouping, it will be refreshed based on the grouped state(expand/collapse). While collapse the group caption row in current viewport then the next view page grouped records are shown.
The collapsed/expanded state will persist only for local dataSource while scrolling.
Group with Page
topic..e-grid .e-row {
height: 2em;
}
selectRows
method is not supported in virtual scrolling.