Virtualization

2 Mar 202224 minutes to read

Grid allows you to load large amount of data without performance degradation.

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 data will be loaded 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 the content area. Also, you have an option to define a visible number of records by
the pageSize property of e-grid-pagesettings tag helper. The loaded data will be cached and reused when it is needed for next time.

<ejs-button id="generate" cssClass="e-info" content="Load 100K Data"></ejs-button>

<ejs-grid id="VirtualGrid" height="600" enableVirtualization="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
    <e-grid-columns>
        <e-grid-column field="Field1" headerText="S.No" width="140" isPrimaryKey="true"></e-grid-column>
        <e-grid-column field="Field2" headerText="Year" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field3" headerText="Stint" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field4" headerText="TMID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field5" headerText="LGID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field6" headerText="GP" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field7" headerText="GS" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field8" headerText="Minutes" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field9" headerText="Points" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field10" headerText="oRebounds" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field11" headerText="dRebounds" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field12" headerText="Rebounds" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field13" headerText="Assists" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field14" headerText="Steals" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field15" headerText="Blocks" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field16" headerText="Turnovers" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field17" headerText="PF" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field18" headerText="fgAttempted" textAlign="Right" width="150"></e-grid-column>
        <e-grid-column field="Field19" headerText="fgMade" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field20" headerText="ftAttempted" textAlign="Right" width="150"></e-grid-column>
        <e-grid-column field="Field21" headerText="ftMade" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field22" headerText="ThreeAttempted" textAlign="Right" width="150"></e-grid-column>
        <e-grid-column field="Field23" headerText="ThreeMade" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field24" headerText="PostGP" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field25" headerText="PostGS" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field26" headerText="PostMinutes" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field27" headerText="PostPoints" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field28" headerText="PostoRebounds" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field29" headerText="PostdRebounds" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field30" headerText="PostRebounds" textAlign="Right" width="130"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

<script>
    var virtualData = [], date1 = null, date2 = null, flag = true;
    var names = ['hardire', 'abramjo01', 'aubucch01', 'Hook', 'Rumpelstiltskin', 'Belle', 'Emma', 'Regina', 'Aurora', 'Elsa',
        'Anna', 'Snow White', 'Prince Charming', 'Cora', 'Zelena', 'August', 'Mulan', 'Graham', 'Discord', 'Will', 'Robin Hood',
        'Jiminy Cricket', 'Henry', 'Neal', 'Red', 'Aaran', 'Aaren', 'Aarez', 'Aarman', 'Aaron', 'Aaron-James', 'Aarron', 'Aaryan', 'Aaryn',
        'Aayan', 'Aazaan', 'Abaan', 'Abbas', 'Abdallah', 'Abdalroof', 'Abdihakim', 'Abdirahman', 'Abdisalam', 'Abdul', 'Abdul-Aziz',
        'Abdulbasir', 'Abdulkadir', 'Abdulkarem', 'Abdulkhader', 'Abdullah', 'Abdul-Majeed', 'Abdulmalik', 'Abdul-Rehman', 'Abdur',
        'Abdurraheem', 'Abdur-Rahman', 'Abdur-Rehmaan', 'Abel', 'Abhinav', 'Abhisumant', 'Abid', 'Abir', 'Abraham', 'Abu', 'Abubakar',
        'Ace', 'Adain', 'Adam', 'Adam-James', 'Addison', 'Addisson', 'Adegbola', 'Adegbolahan', 'Aden', 'Adenn', 'Adie', 'Adil', 'Aditya',
        'Adnan', 'Adrian', 'Adrien', 'Aedan', 'Aedin', 'Aedyn', 'Aeron', 'Afonso', 'Ahmad', 'Ahmed', 'Ahmed-Aziz', 'Ahoua', 'Ahtasham',
        'Aiadan', 'Aidan', 'Aiden', 'Aiden-Jack', 'Aiden-Vee'];


    document.getElementById("generate").addEventListener('click', () => {

        var grid = document.getElementById("VirtualGrid").ej2_instances[0];
        if (!virtualData.length) {
            dataSource();
            date1 = new Date().getTime();
            grid.dataSource = virtualData;
        } else {
            flag = true;
            show();
            date1 = new Date().getTime();
            grid.refresh();
        }
    })

    function dataSource() {
        for (var i = 0; i < 100000; i++) {
            virtualData.push({
                'Field1': i + 1,
                'Field2': 1967 + (i % 10),
                'Field3': Math.floor(Math.random() * 200),
                'Field4': Math.floor(Math.random() * 100),
                'Field5': Math.floor(Math.random() * 2000),
                'Field6': Math.floor(Math.random() * 1000),
                'Field7': Math.floor(Math.random() * 100),
                'Field8': Math.floor(Math.random() * 10),
                'Field9': Math.floor(Math.random() * 10),
                'Field10': Math.floor(Math.random() * 100),
                'Field11': Math.floor(Math.random() * 100),
                'Field12': Math.floor(Math.random() * 1000),
                'Field13': Math.floor(Math.random() * 10),
                'Field14': Math.floor(Math.random() * 10),
                'Field15': Math.floor(Math.random() * 1000),
                'Field16': Math.floor(Math.random() * 200),
                'Field17': Math.floor(Math.random() * 300),
                'Field18': Math.floor(Math.random() * 400),
                'Field19': Math.floor(Math.random() * 500),
                'Field20': Math.floor(Math.random() * 700),
                'Field21': Math.floor(Math.random() * 800),
                'Field22': Math.floor(Math.random() * 1000),
                'Field23': Math.floor(Math.random() * 2000),
                'Field24': Math.floor(Math.random() * 150),
                'Field25': Math.floor(Math.random() * 1000),
                'Field26': Math.floor(Math.random() * 100),
                'Field27': Math.floor(Math.random() * 400),
                'Field28': Math.floor(Math.random() * 600),
                'Field29': Math.floor(Math.random() * 500),
                'Field30': Math.floor(Math.random() * 300),
            });
        }
    }
</script>
public IActionResult Index()
 {
    return View();
 }

Column Virtualization

Column virtualization allows you to virtualize columns. It will render columns which are in the viewport. You can scroll horizontally to view more columns.

To setup the column virtualization, set the enableVirtualization and enableColumnVirtualization properties as true.

<ejs-button id="generate" cssClass="e-info" content="Load 100K Data"></ejs-button>

<ejs-grid id="VirtualGrid" height="600" enableVirtualization="true" enableColumnVirtualization="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
    <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings>
    <e-grid-columns>
        <e-grid-column field="Field1" headerText="S.No" width="140" isPrimaryKey="true"></e-grid-column>
        <e-grid-column field="Field2" headerText="Year" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field3" headerText="Stint" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field4" headerText="TMID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field5" headerText="LGID" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field6" headerText="GP" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field7" headerText="GS" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field8" headerText="Minutes" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field9" headerText="Points" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field10" headerText="oRebounds" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field11" headerText="dRebounds" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field12" headerText="Rebounds" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field13" headerText="Assists" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field14" headerText="Steals" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field15" headerText="Blocks" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field16" headerText="Turnovers" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field17" headerText="PF" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field18" headerText="fgAttempted" textAlign="Right" width="150"></e-grid-column>
        <e-grid-column field="Field19" headerText="fgMade" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field20" headerText="ftAttempted" textAlign="Right" width="150"></e-grid-column>
        <e-grid-column field="Field21" headerText="ftMade" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field22" headerText="ThreeAttempted" textAlign="Right" width="150"></e-grid-column>
        <e-grid-column field="Field23" headerText="ThreeMade" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field24" headerText="PostGP" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field25" headerText="PostGS" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field26" headerText="PostMinutes" textAlign="Right" width="120"></e-grid-column>
        <e-grid-column field="Field27" headerText="PostPoints" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field28" headerText="PostoRebounds" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field29" headerText="PostdRebounds" textAlign="Right" width="130"></e-grid-column>
        <e-grid-column field="Field30" headerText="PostRebounds" textAlign="Right" width="130"></e-grid-column>
    </e-grid-columns>
</ejs-grid>

<script>
    var virtualData = [], date1 = null, date2 = null, flag = true;
    var names = ['hardire', 'abramjo01', 'aubucch01', 'Hook', 'Rumpelstiltskin', 'Belle', 'Emma', 'Regina', 'Aurora', 'Elsa',
        'Anna', 'Snow White', 'Prince Charming', 'Cora', 'Zelena', 'August', 'Mulan', 'Graham', 'Discord', 'Will', 'Robin Hood',
        'Jiminy Cricket', 'Henry', 'Neal', 'Red', 'Aaran', 'Aaren', 'Aarez', 'Aarman', 'Aaron', 'Aaron-James', 'Aarron', 'Aaryan', 'Aaryn',
        'Aayan', 'Aazaan', 'Abaan', 'Abbas', 'Abdallah', 'Abdalroof', 'Abdihakim', 'Abdirahman', 'Abdisalam', 'Abdul', 'Abdul-Aziz',
        'Abdulbasir', 'Abdulkadir', 'Abdulkarem', 'Abdulkhader', 'Abdullah', 'Abdul-Majeed', 'Abdulmalik', 'Abdul-Rehman', 'Abdur',
        'Abdurraheem', 'Abdur-Rahman', 'Abdur-Rehmaan', 'Abel', 'Abhinav', 'Abhisumant', 'Abid', 'Abir', 'Abraham', 'Abu', 'Abubakar',
        'Ace', 'Adain', 'Adam', 'Adam-James', 'Addison', 'Addisson', 'Adegbola', 'Adegbolahan', 'Aden', 'Adenn', 'Adie', 'Adil', 'Aditya',
        'Adnan', 'Adrian', 'Adrien', 'Aedan', 'Aedin', 'Aedyn', 'Aeron', 'Afonso', 'Ahmad', 'Ahmed', 'Ahmed-Aziz', 'Ahoua', 'Ahtasham',
        'Aiadan', 'Aidan', 'Aiden', 'Aiden-Jack', 'Aiden-Vee'];


    document.getElementById("generate").addEventListener('click', () => {

        var grid = document.getElementById("VirtualGrid").ej2_instances[0];
        if (!virtualData.length) {
            dataSource();
            date1 = new Date().getTime();
            grid.dataSource = virtualData;
        } else {
            flag = true;
            show();
            date1 = new Date().getTime();
            grid.refresh();
        }
    })

    function dataSource() {
        for (var i = 0; i < 100000; i++) {
            virtualData.push({
                'Field1': i + 1,
                'Field2': 1967 + (i % 10),
                'Field3': Math.floor(Math.random() * 200),
                'Field4': Math.floor(Math.random() * 100),
                'Field5': Math.floor(Math.random() * 2000),
                'Field6': Math.floor(Math.random() * 1000),
                'Field7': Math.floor(Math.random() * 100),
                'Field8': Math.floor(Math.random() * 10),
                'Field9': Math.floor(Math.random() * 10),
                'Field10': Math.floor(Math.random() * 100),
                'Field11': Math.floor(Math.random() * 100),
                'Field12': Math.floor(Math.random() * 1000),
                'Field13': Math.floor(Math.random() * 10),
                'Field14': Math.floor(Math.random() * 10),
                'Field15': Math.floor(Math.random() * 1000),
                'Field16': Math.floor(Math.random() * 200),
                'Field17': Math.floor(Math.random() * 300),
                'Field18': Math.floor(Math.random() * 400),
                'Field19': Math.floor(Math.random() * 500),
                'Field20': Math.floor(Math.random() * 700),
                'Field21': Math.floor(Math.random() * 800),
                'Field22': Math.floor(Math.random() * 1000),
                'Field23': Math.floor(Math.random() * 2000),
                'Field24': Math.floor(Math.random() * 150),
                'Field25': Math.floor(Math.random() * 1000),
                'Field26': Math.floor(Math.random() * 100),
                'Field27': Math.floor(Math.random() * 400),
                'Field28': Math.floor(Math.random() * 600),
                'Field29': Math.floor(Math.random() * 500),
                'Field30': Math.floor(Math.random() * 300),
            });
        }
    }
</script>
public IActionResult Index()
 {
    return View();
 }

Column’s width is required for column virtualization. If column’s width is not defined then Grid will consider its value as 200px.

Virtualization with Grouping

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.

Limitations for virtual scrolling

  • While using column virtual scrolling, column width should be in the pixel. Percentage values are not accepted.
  • Due to the element height limitation in browsers, the maximum number of records loaded by the grid is limited by the browser capability.
  • Cell selection will not be persisted in both row and column virtual scrolling.
  • Virtual scrolling is not compatible with batch editing, detail template and hierarchy features.
  • Group expand and collapse state will not be persisted.
  • Since data is virtualized in grid, 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 Group with Page topic.
  • The page size provided must be two times larger than the number of visible rows in the grid. If the page size is failed to meet this condition then the size will be determined by grid.
  • The height of the grid 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-grid .e-row {
    height: 2em;
}
  • Programmatic selection using the selectRows method is not supported in virtual scrolling.