Data Grid Rendering & Scrolling

Data rendering, paging and scrolling operations.

Examples

About

Sometimes your data set is too large to display all on one page. Ext.grid.Panel supports displaying individual pages from the dataset using a Ext.toolbar.Paging, which loads pages using previous/next buttons.

Store Setup

Before we can set up paging on a Ext.grid.Panel, we have to configure the Ext.data.Store to support paging. In the below example we add Ext.data.Store#cfg-pageSize to the Ext.data.Store, and we configure our Ext.data.reader.Reader with a Ext.data.reader.Reader#cfg-totalProperty:

  1. Ext.create('Ext.data.Store', {
  2. model: 'User',
  3. autoLoad: true,
  4. pageSize: 100,
  5. proxy: {
  6. type: 'ajax',
  7. url : 'data/users.json',
  8. reader: {
  9. type: 'json',
  10. rootProperty: 'users',
  11. totalProperty: 'total'
  12. }
  13. }
  14. });

The Ext.data.reader.Reader#totalProperty config tells Ext.data.reader.Json where to get the total number of results in the JSON response. This Ext.data.Store is configured to consume a JSON response that looks something like this:

  1. {
  2. "success": true,
  3. "total": 4,
  4. "users": [
  5. { "name": "Lisa", "email": "[email protected]", "phone": "555-111-1224" },
  6. { "name": "Bart", "email": "[email protected]", "phone": "555-222-1234" },
  7. { "name": "Homer", "email": "[email protected]", "phone": "555-222-1244" },
  8. { "name": "Marge", "email": "[email protected]", "phone": "555-222-1254" }
  9. ]
  10. }

Paging Toolbar

Now that we’ve set up our Ext.data.Store to support paging, all that’s left is to configure a Ext.toolbar.Paging. You could put the Ext.toolbar.Paging anywhere in your application layout, but typically it is docked to the Ext.grid.Panel:

  1. Ext.create('Ext.grid.Panel', {
  2. store: userStore,
  3. columns: ...,
  4. dockedItems: [{
  5. xtype: 'pagingtoolbar',
  6. store: userStore, // same store GridPanel is using
  7. dock: 'bottom',
  8. displayInfo: true
  9. }]
  10. });

Rendering & Scrolling - 图1

See the Paging Grid for a working example.

Buffered Rendering

Grids and Trees enable buffered rendering of extremely large datasets as an alternative to using a paging toolbar. Your users can scroll through thousands of records without the performance penalties of rendering all the records on screen at once.

Only enough rows are rendered to fill the visible area of the Grid with a little Ext.grid.Panel#cfg-leadingBufferZone overflow either side to allow scrolling. As scrolling proceeds, new rows are rendered in the direction of scroll, and rows are removed from the receding side of the table.

Grids use buffered rendering by default, so you no longer need to add the plugin to your Grid component.

See Big Data of Filtered Tree for working examples.

Embedded components.

Since ExtJS 5.0, developers have had the ability to embed components within grid cells using the Widget Column class.

In versions prior to 6.2.0, components embedded in this way had no access to the grid’s Ext.app.ViewModel. The field referenced by the column’s dataIndex was bound to the component’s defaultBindProperty.

In 6.2.0+, components embedded in grids have access to the ViewModel and all the data within it. The ViewModel contains two row-specific properties:

  1. record
  2. recordIndex

Since ExtJS 6.2.0, developers have had the ability to configure a component to be displayed in an expansion row below (or, configurably, above) the data row.

The embedded component has access to the grid’s ViewModel.

See Using Components in Grids guide for more details.