PagingToolbar没有读取数据 - Ext JS

时间:2014-03-11 20:25:42

标签: extjs

我似乎无法让PagingToolbar在我的网格上正常工作。无论如何,它告诉我返回0结果,即使我收回了所有数据。

Ext.onReady(function() {
    var data = '{"elements":[{"element":{"name":"value 1","id":"element 1","attributes":[{"attrname":"id","attrvalue":"This is the ID"},{"attrname":"name","attrvalue":"This is the name"},{"attrname":"description","attrvalue":"This is the description"},{"attrname":"table_name","attrvalue":"This is the table"}]}},{"element":{"name":"value 2","id":"element 2","attributes":[{"attrname":"id","attrvalue":"This is the ID 2"},{"attrname":"name","attrvalue":"This is the name 2"},{"attrname":"description","attrvalue":"This is the description 2"},{"attrname":"table_name","attrvalue":"This is the table 2"}]}}]}';
    var store = Ext.create('Ext.data.Store', {
        fields: ['id', 'name', 'description', 'table_name'],
        proxy: {
            type: 'memory'
        }
    })
    Ext.create('Ext.grid.Panel', {
        title: 'Test Data',
        store: store,
        pageSize: 2
        columns: [{
            text: 'ID',
            dataIndex: 'id'
        }, {
            text: 'Name',
            dataIndex: 'name'
        }, {
            text: 'Description',
            dataIndex: 'description'
        }, {
            text: 'Table Name',
            dataIndex: 'table_name'
        }],
        dockedItems: [{
            xtype: 'pagingtoolbar',
            store: store,
            pageSize: 2,
            dock: 'bottom',
            displayInfo: true
        }]
        renderTo: Ext.getBody()
    });
    var decoded = Ext.decode( data );
    // loop over decoded data
    for( var i=0; i<decoded.elements.length; i++ ) {
        var element = decoded.elements[ i ].element;
        // set implicit model
        var model = {};
        // loop over attributes
        for( var x=0; x<element.attributes.length; x++ ) {
            var attribute = element.attributes[ x ];
            model[ attribute.attrname ] = attribute.attrvalue;
        }
        // implicitly cast data as Model
        store.add( model );
    }
})

帮助?

1 个答案:

答案 0 :(得分:0)

尝试使用Ext.ux.data.PagingMemoryProxy

  

分页内存代理,允许在内存数据集中使用分页网格