ExtJS Grid Paging: next button is disabled!

左心房为你撑大大i 提交于 2019-12-13 00:23:37

问题


I created a basic grid that has a paging toolbar. For some reason when I load up at index 0, the Next Page button is disabled, even though the text says "Displaying page 1 of 5". If I choose anything higher than 0 in the load params for the store, it allows me to page forward and back, but it does not properly display the max # of pages and if I go back to the first page, the next button is once again disabled.

Any ideas?

function getBugGrid(activityPanelWrapper){
  var pageSize = 5;
  var bugStore = new Ext.data.JsonStore({
                                          reader: new Ext.data.JsonReader({
                                                                            totalProperty: 'total_count'
                                                                          }),
                                          autoLoad: {params:{start: 0, limit: pageSize}},
                                          autoDestroy: true,
                                          url: '/bugs/fetch',
                                          idProperty: 'id',
                                          region: 'center',
                                          root: 'data',
                                          storeId: 'bugStore',
                                          fields: [...]
                                        });

  var columnModel = new Ext.grid.ColumnModel({
                                               defaults: {
                                                 width: 120,
                                                 sortable: true
                                               },
                                               columns: [...]
                                             });

  return new Ext.grid.GridPanel({
                                      region: 'center',
                                      store: bugStore,
                                      colModel: columnModel,
                                      trackMouseOver:false,
                                      loadMask: true,
                                      sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
                                      listeners: {
                                        rowclick: {
                                          fn: function(grid, rowIndex, event) {
                                            var bug_id = grid.store.getAt(rowIndex).id;
                                            Ext.getCmp('activity-panel').load(activity_lines_path(bug_id));
                                          }
                                        }
                                      },
                                      bbar: new Ext.PagingToolbar({
                                                                    pageSize: pageSize,
                                                                    store: bugStore,
                                                                    displayInfo: true,
                                                                    displayMsg: 'Displaying topics {0} - {1} of {2}',
                                                                    emptyMsg: "No topics to display"
                                                                  })
                                    });
}

JSON response:

{"data":[{ bug 1 },{ bug 2 },{ bug 3 },{ bug 4 },{ bug 5 }],
 "errors":{},
 "total_count":25}

回答1:


You are not reading the TotalProperty in the JsonReader...

You need to add this config to your autoLoad...

var bugStore = new Ext.data.JsonStore({
  autoDestroy: true,
  url: '/bugs/fetch',
  idProperty: 'id',
  root: 'data',
  storeId: 'bugStore',
  fields: [ ... ]
  autoLoad: {params:{start: 0, limit: pagesize}}
});

You can also define a JSON reader in your JSON store:

var myStore = new Ext.data.Store({
reader: new Ext.data.JsonReader({
    totalProperty: 'total_count', 
    ...
}),
...

});



来源:https://stackoverflow.com/questions/4226311/extjs-grid-paging-next-button-is-disabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!