代码之家  ›  专栏  ›  技术社区  ›  Josiah Kiehl

ExtJS网格分页:下一步按钮被禁用!

  •  1
  • Josiah Kiehl  · 技术社区  · 14 年前

    我创建了一个具有分页工具栏的基本网格。出于某种原因,当我加载到索引0时,“下一页”按钮被禁用,即使文本显示“显示第1页,共5页”。如果我在商店的加载参数中选择了高于0的内容,它允许我前后翻页,但它不能正确显示最大页数,如果我返回第一页,则再次禁用“下一步”按钮。

    有什么想法吗?

    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响应:

    {"data":[{ bug 1 },{ bug 2 },{ bug 3 },{ bug 4 },{ bug 5 }],
     "errors":{},
     "total_count":25}
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   It Grunt    14 年前

    您没有在jsonreader中读取totalproperty…

    您需要将此配置添加到自动加载中…

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

    您还可以在JSON存储区中定义一个JSON阅读器:

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

    (});