Virtual scroll in Vue Treegrid component
11 Jun 202417 minutes to read
TreeGrid allows you to load large amount of data without performance degradation.
To use virtualization, you need to inject VirtualScroll
module in the provide
section.
Row virtualization
Row virtualization allows you to load and render rows only in the content viewport. It is an alternative way of paging in which the rows will be appended 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 TreeGrid is determined implicitly by height of the content area and a buffer records will be maintained in the TreeGrid content in addition to the original set of rows.
Expand and Collapse state of any child record will be persisted.
<template>
<div id="app">
<ejs-treegrid ref='treegrid' :dataSource="virtualData" :enableVirtualization='true' :treeColumnIndex='1' childMapping='Crew' height=317>
<e-columns>
<e-column field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></e-column>
<e-column field='FIELD1' headerText='Player Name' width='120'></e-column>
<e-column field='FIELD2' headerText='Year' width='100' textAlign='Right'></e-column>
<e-column field='FIELD3' headerText='Stint' width='120' textAlign='Right'></e-column>
<e-column field='FIELD4' headerText='TMID' width='120' textAlign='Right'></e-column>
<e-column field='FIELD5' headerText='LGID' width='120' textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script setup>
import { provide } from "vue";
import { TreeGridComponent as EjsTreegrid, VirtualScroll, ColumnDirective as EColumn, ColumnsDirective as EColumns } from "@syncfusion/ej2-vue-treegrid";
import { dataSource, virtualData } from "./datasource.js";
const virtualData = dataSource();
provide('treegrid', [VirtualScroll]);
</script>
<template>
<div id="app">
<ejs-treegrid ref='treegrid' :dataSource="virtualData" :enableVirtualization='true' :treeColumnIndex='1' childMapping='Crew' height=317>
<e-columns>
<e-column field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></e-column>
<e-column field='FIELD1' headerText='Player Name' width='120'></e-column>
<e-column field='FIELD2' headerText='Year' width='100' textAlign='Right'></e-column>
<e-column field='FIELD3' headerText='Stint' width='120' textAlign='Right'></e-column>
<e-column field='FIELD4' headerText='TMID' width='120' textAlign='Right'></e-column>
<e-column field='FIELD5' headerText='LGID' width='120' textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import { TreeGridComponent, VirtualScroll } from "@syncfusion/ej2-vue-treegrid";
import { dataSource, virtualData } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-treegrid":TreeGridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
},
data () {
return {
virtualData: dataSource(),
};
},
provide: {
treegrid: [VirtualScroll]
}
}
</script>
Column virtualization
Column virtualization allows you to virtualize columns. It will render column only in the current view port and all other columns are rendered on demand during horizontal scrolling.
To setup the column virtualization, set the enableVirtualization
and enableColumnVirtualization
properties as true
.
<template>
<div id="app">
<ejs-treegrid ref='treegrid' :dataSource="virtualData" :enableVirtualization='true' :enableColumnVirtualization='true' :treeColumnIndex='1' childMapping='Crew' height=317>
<e-columns>
<e-column field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></e-column>
<e-column field='FIELD1' headerText='Player Name' width='120'></e-column>
<e-column field='FIELD2' headerText='Year' width='100' textAlign='Right'></e-column>
<e-column field='FIELD3' headerText='Stint' width='120' textAlign='Right'></e-column>
<e-column field='FIELD4' headerText='TMID' width='120' textAlign='Right'></e-column>
<e-column field='FIELD5' headerText='LGID' width='120' textAlign='Right'></e-column>
<e-column field='FIELD5' headerText='LGID' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD6' headerText='GP' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD7' headerText='GS' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD8' headerText='Minutes' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD9' headerText='Points' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD10' headerText='oRebounds' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD11' headerText='dRebounds' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD12' headerText='Rebounds' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD13' headerText='Assists' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD14' headerText='Steals' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD15' headerText='Blocks' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD16' headerText='Turnovers' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD17' headerText='PF' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD18' headerText='fgAttempted' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD19' headerText='ftAttempted' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD20' headerText='ThreeAttempted' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD21' headerText='ThreeMade' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD22' headerText='PostGP' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD23' headerText='ftMade' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD24' headerText='fgMade' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD25' headerText='ffmade' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD26' headerText='PostGS' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD27' headerText='PostMinutes' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD28' headerText='PostPoints' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD29' headerText='PostoRebounds' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD30' headerText='PostdRebounds' width= 120 textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script setup>
import { provide } from "vue";
import { TreeGridComponent as EjsTreegrid, VirtualScroll, ColumnDirective as EColumn,
ColumnsDirective as EColumns
} from "@syncfusion/ej2-vue-treegrid";
import { dataSource, virtualData } from "./datasource.js";
const virtualData = dataSource();
provide('treegrid', [VirtualScroll]);
</script>
<template>
<div id="app">
<ejs-treegrid ref='treegrid' :dataSource="virtualData" :enableVirtualization='true' :enableColumnVirtualization='true' :treeColumnIndex='1' childMapping='Crew' height=317>
<e-columns>
<e-column field='TaskID' headerText='Player Jersey' width='120' textAlign='Right'></e-column>
<e-column field='FIELD1' headerText='Player Name' width='120'></e-column>
<e-column field='FIELD2' headerText='Year' width='100' textAlign='Right'></e-column>
<e-column field='FIELD3' headerText='Stint' width='120' textAlign='Right'></e-column>
<e-column field='FIELD4' headerText='TMID' width='120' textAlign='Right'></e-column>
<e-column field='FIELD5' headerText='LGID' width='120' textAlign='Right'></e-column>
<e-column field='FIELD5' headerText='LGID' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD6' headerText='GP' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD7' headerText='GS' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD8' headerText='Minutes' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD9' headerText='Points' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD10' headerText='oRebounds' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD11' headerText='dRebounds' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD12' headerText='Rebounds' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD13' headerText='Assists' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD14' headerText='Steals' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD15' headerText='Blocks' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD16' headerText='Turnovers' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD17' headerText='PF' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD18' headerText='fgAttempted' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD19' headerText='ftAttempted' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD20' headerText='ThreeAttempted' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD21' headerText='ThreeMade' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD22' headerText='PostGP' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD23' headerText='ftMade' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD24' headerText='fgMade' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD25' headerText='ffmade' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD26' headerText='PostGS' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD27' headerText='PostMinutes' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD28' headerText='PostPoints' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD29' headerText='PostoRebounds' width= 120 textAlign='Right'></e-column>
<e-column field='FIELD30' headerText='PostdRebounds' width= 120 textAlign='Right'></e-column>
</e-columns>
</ejs-treegrid>
</div>
</template>
<script>
import { TreeGridComponent, VirtualScroll, ColumnDirective, ColumnsDirective } from "@syncfusion/ej2-vue-treegrid";
import { dataSource, virtualData } from "./datasource.js";
export default {
name: "App",
components: {
"ejs-treegrid":TreeGridComponent,
"e-columns":ColumnsDirective,
"e-column":ColumnDirective,
},
data () {
return {
virtualData: dataSource(),
};
},
provide: {
treegrid: [VirtualScroll]
}
}
</script>
Column’s
width
is required for column virtualization. If column’s width is not defined then tree grid will consider its value as200px
.
Limitations for virtualization
- Due to the element height limitation in browsers, the maximum number of records loaded by the treegrid is limited by the browser capability.
- Cell selection will not be persisted in row.
- Virtual scrolling is not compatible with detail template,clipboard functionality, Batch editing and row drag and drop features.
- The page size provided must be two times larger than the number of visible rows in the TreeGrid. If the page size is failed to meet this condition then the size will be determined by TreeGrid.
- The virtual height of the treegrid content is calculated using the row height and total number of records in the data source and hence features which changes row height such as text wrapping are not supported. If you want to increase the row height to accommodate the content then you can specify the row height as below to ensure all the table rows are in same height.
.e-treegrid .e-row {
height: 2em;
}
- Programmatic selection using the selectRows method is not supported in virtual scrolling.
- When virtualization is active in a tree grid, the editCell method is unusable for records outside the currently visible viewport.