Paging toolbar on custom component querying local data store

a 夏天 提交于 2019-12-11 02:49:02

问题


I have a few questions regarding paging a Ext Store.

The Store will pull an amount of historical data on page load.

If the number of records is greater than 10 then I need to implement paging on a custom component/view. The view will be generated with Ext.view.View and a XTemplate.

I would like to know if i can use the paging toolbar on a custom component and if i can query a Store where all the data is held locally. Therefore, not passing parameters to the server and pulling new data back but querying the data Store itself and displaying the results to the user.


回答1:


It is possible using the Ext.ux.data.PagingMemoryProxy proxy. It is located in examples\ux\data\PagingMemoryProxy.js

The follow example show you how to paging images in a custom view create with generated with Ext.view.View and a XTemplate:

Ext.define('Image', {
    extend: 'Ext.data.Model',
    fields: [
        { name:'src', type:'string' },
        { name:'caption', type:'string' }
    ]
});

Ext.create('Ext.data.Store', {
    id:'imagesStore',
    model: 'Image',
    proxy: {
        type: 'pagingmemory'
    },
    data: [
        { src:'http://www.sencha.com/img/20110215-feat-drawing.png', caption:'Drawing & Charts' },
        { src:'http://www.sencha.com/img/20110215-feat-data.png', caption:'Advanced Data' },
        { src:'http://www.sencha.com/img/20110215-feat-html5.png', caption:'Overhauled Theme' },
        { src:'http://www.sencha.com/img/20110215-feat-perf.png', caption:'Performance Tuned' }
    ],
    pageSize: 2
});

var imageTpl = new Ext.XTemplate(
    '<tpl for=".">',
        '<div style="margin-bottom: 10px;" class="thumb-wrap">',
          '<img src="{src}" />',
          '<br/><span>{caption}</span>',
        '</div>',
    '</tpl>'
);

var store = Ext.data.StoreManager.lookup('imagesStore');
Ext.create('Ext.panel.Panel', {
    title: 'Pictures',
    autoScroll: true,
    height: 300,
    items: {
        xtype: 'dataview',
        store: store,
        tpl: imageTpl,
        itemSelector: 'div.thumb-wrap',
        emptyText: 'No images available'
    },    
    dockedItems: [{
         xtype: 'pagingtoolbar',
         store: store,
         dock: 'bottom',
         displayInfo: true
     }],    
    renderTo: Ext.getBody()
});​

You can see it working in jsfiddle.net: http://jsfiddle.net/lontivero/QHDZU/

I hope this is useful.

Good luck!



来源:https://stackoverflow.com/questions/13778444/paging-toolbar-on-custom-component-querying-local-data-store

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