1

我有一个基本的网格面板,它来自一个有 600 条记录的商店,但是我的分页工具栏只显示第一页,而不管pageSize商店中的配置如何。例如...

当 时pageSize = 50,分页工具栏显示:

Page 1 of 1 | Displaying 1 - 50 of 50

当 时pageSize = 100,分页工具栏显示:

Page 1 of 1 | Displaying 1 - 100 of 100

想法?来源如下。

employee_store.js

var empUrlRoot = 'http://extjsinaction.com/crud.php'
                    + '?model=Employee&method=';

//Instantiate employee store
var employeeStore = Ext.create('Ext.data.Store', {
    model: 'Employee',
    pageSize: 50,
    proxy: {
        type: 'jsonp',
        api: {
            create: empUrlRoot + 'CREATE',
            read: empUrlRoot + 'READ',
            udpate: empUrlRoot + 'UPDATE',
            destroy: empUrlRoot + 'DESTROY'
        },
        reader: {
            type: 'json',
            metaProperty: 'meta',
            root: 'data',
            idProperty: 'id',
            successProperty: 'meta.success'
        },
        writer: {
            type: 'json',
            encode: true,
            writeAllFields: true,
            root: 'data',
            allowSingle: true,
            batch: false,
            writeRecords: function(request, data){
                request.jsonData = data;
                return request;
            }
        }
    }
});

gridpanel.js

Ext.onReady(function(){

    // gridpanel column configurations
    var columns = [
        {
            xtype: 'templatecolumn',
            header: 'ID',
            dataIndex: 'id',
            sortable: true,
            width: 50,
            resizable: false,
            hidden: true,
            // template renders id column blue:
            tpl: '<span style="color: #0000FF;">{id}</span>'
        },
        {
            header: 'Last Name',
            dataIndex: 'lastName',
            sortable: true,
            hideable: false,
            width: 100
        },
        {
            header: 'First Name',
            dataIndex: 'firstName',
            sortable: true,
            hideable: false,
            width: 100
        },
        {
            header: 'Address',
            dataIndex: 'street',
            sortable: false,
            flex: 1,
            // template renders column with additional content:
            tpl: '{street}<br />{city} {state}, {zip}'
        }
    ];

    // Configure the gridpanel paging toolbar
    var pagingtoolbar = {
        xtype: 'pagingtoolbar',
        store: employeeStore,
        dock: 'bottom',
        displayInfo: true
    };

    // Create gridpanel
    var grid = Ext.create('Ext.grid.Panel', {
        xtype: 'grid',
        columns: columns,
        store: employeeStore,
        loadMask: true,
        selType: 'rowmodel',
        singleSelect: true,
        stripeRows: true,
        dockedItems: [
            pagingtoolbar
        ]
    });

    // Configure and create container for gridpanel
    Ext.create('Ext.Window', {
        height: 350,
        width: 550,
        border: false,
        layout: 'fit',
        items: grid //the gridpanel
    }).show();

    // Load the employeeStore
    employeeStore.load();

});

员工模型.js

// Define employee model
Ext.define('Employee', {
    extend: 'Ext.data.Model',
    idProperty: 'id',
    fields: [
    {name: 'id',type: 'int'},
    {name: 'departmentId', type: 'int' },
    {name:'dateHired', type:'date', format:'Y-m-d'},
    {name:'dateFired', type:'date', format:'Y-m-d'},
    {name:'dob', type:'date', format: 'Y-m-d'},
    'firstName',
    'lastName',
    'title',
    'street',
    'city',
    'state',
    'zip'
    ]
});
4

1 回答 1

3

您必须返回总记录数。

reader: {
  root : 'data',
  totalProperty: 'total' // this is default, you can change it
}

接下来在服务器响应中,您需要:

{
    data : ['your data here'],
    total : 2000
}
于 2014-07-23T17:28:36.153 回答