ExtJS ArrayStore 的分页问题

发布于 2024-11-30 09:40:14 字数 865 浏览 1 评论 0原文

我正在 ExtJS 中尝试一些东西,包括显示具有不同功能的网格。

在我的页面中,我首先声明一个包含大约一百个数据的 Javascript 数组,并将其存储在名为 myArray 的变量中。

然后,我执行以下操作:

Ext.define('Fund2',{
extend:'Ext.data.Model',
fields:[{name:'Id'},
{name:'Id2'},
{name:'Name'},
{name:'Name2'},
{name:'Name3'},
{name:'Name4'},
{name:'Param1'},
{name:'Param2'},
{name:'Param3'}]
});

var myStore2=Ext.create('Ext.data.ArrayStore',{
model:'Fund2',
data:myArray,
pageSize:10
});

Ext.create('Ext.grid.Panel',{
renderTo:'div2',
store:myStore2,
height:500,
width:500,
columns:[{text:'Id',dataIndex:'Id'},
{text:'Name',dataIndex:'Name'},
{text:'Additional',dataIndex:'Param1'}],
dockedItems:[{
xtype: 'pagingtoolbar',
store:myStore2,
dock: 'bottom',
displayInfo: true
}]
});

在页面上,网格面板正确显示并填充数据。

分页工具栏也可用并计算正确的页面数量。

然而,数据并没有被“分页”;所有记录都显示在网格中。

你知道我哪里做错了吗?

I am trying out a few things in ExtJS including displaying a grid with different functionalities.

In my page, I first declare a Javascript Array of about a hundred data which I store in a variable called myArray

Then, I do the following:

Ext.define('Fund2',{
extend:'Ext.data.Model',
fields:[{name:'Id'},
{name:'Id2'},
{name:'Name'},
{name:'Name2'},
{name:'Name3'},
{name:'Name4'},
{name:'Param1'},
{name:'Param2'},
{name:'Param3'}]
});

var myStore2=Ext.create('Ext.data.ArrayStore',{
model:'Fund2',
data:myArray,
pageSize:10
});

Ext.create('Ext.grid.Panel',{
renderTo:'div2',
store:myStore2,
height:500,
width:500,
columns:[{text:'Id',dataIndex:'Id'},
{text:'Name',dataIndex:'Name'},
{text:'Additional',dataIndex:'Param1'}],
dockedItems:[{
xtype: 'pagingtoolbar',
store:myStore2,
dock: 'bottom',
displayInfo: true
}]
});

On th page, the grid panel is displayed properly and filled with the data.

The paging toolbar is also available and computes the right amount of pages.

However, the data is not "paged"; all the records are shown in the grid.

Do you know where I made a mistake?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾城泪 2024-12-07 09:40:14

添加此:

myStore2.on('load', function(store, records, successful, operation) {
            this.loadData(myArray.slice((this.currentPage-1)*PAGE_SIZE, (this.currentPage)*PAGE_SIZE));
        },myStore2);

完整版:

Ext.onReady(function(){
    var myArray=[];
    for (var i=0; i<100; i++) {
        myArray[i] = ['Id_'+i,'Id2_'+i,'Name_'+i,'Name2_'+i,'Name3_'+i,'Name4_'+i,'Param1_'+i,'Param2_'+i,'Param3_'+i];
    }
    var PAGE_SIZE = 10;

    Ext.define('Fund2',{
        extend:'Ext.data.Model',
        fields:[{name:'Id'},{name:'Id2'},{name:'Name'},{name:'Name2'},{name:'Name3'},{name:'Name4'},{name:'Param1'},{name:'Param2'},{name:'Param3'}]});

    var myStore2=Ext.create('Ext.data.ArrayStore',{
        model:'Fund2',
        data:myArray,
        pageSize:PAGE_SIZE
    });

    myStore2.on('load', function(store, records, successful, operation) {
        this.loadData(myArray.slice((this.currentPage-1)*PAGE_SIZE, (this.currentPage)*PAGE_SIZE));
    },myStore2);

    myStore2.load();

    Ext.create('Ext.grid.Panel',{
        renderTo:Ext.getBody(),
        store:myStore2,
        height:500,
        width:500,
        columns:[{text:'Id',dataIndex:'Id'},
                 {text:'Name',dataIndex:'Name'},
                 {text:'Additional',dataIndex:'Param1'}],
        dockedItems:[{
            xtype: 'pagingtoolbar',
            store:myStore2,dock: 'bottom',
            displayInfo: true
        }]
    });
});

Add this:

myStore2.on('load', function(store, records, successful, operation) {
            this.loadData(myArray.slice((this.currentPage-1)*PAGE_SIZE, (this.currentPage)*PAGE_SIZE));
        },myStore2);

Full version:

Ext.onReady(function(){
    var myArray=[];
    for (var i=0; i<100; i++) {
        myArray[i] = ['Id_'+i,'Id2_'+i,'Name_'+i,'Name2_'+i,'Name3_'+i,'Name4_'+i,'Param1_'+i,'Param2_'+i,'Param3_'+i];
    }
    var PAGE_SIZE = 10;

    Ext.define('Fund2',{
        extend:'Ext.data.Model',
        fields:[{name:'Id'},{name:'Id2'},{name:'Name'},{name:'Name2'},{name:'Name3'},{name:'Name4'},{name:'Param1'},{name:'Param2'},{name:'Param3'}]});

    var myStore2=Ext.create('Ext.data.ArrayStore',{
        model:'Fund2',
        data:myArray,
        pageSize:PAGE_SIZE
    });

    myStore2.on('load', function(store, records, successful, operation) {
        this.loadData(myArray.slice((this.currentPage-1)*PAGE_SIZE, (this.currentPage)*PAGE_SIZE));
    },myStore2);

    myStore2.load();

    Ext.create('Ext.grid.Panel',{
        renderTo:Ext.getBody(),
        store:myStore2,
        height:500,
        width:500,
        columns:[{text:'Id',dataIndex:'Id'},
                 {text:'Name',dataIndex:'Name'},
                 {text:'Additional',dataIndex:'Param1'}],
        dockedItems:[{
            xtype: 'pagingtoolbar',
            store:myStore2,dock: 'bottom',
            displayInfo: true
        }]
    });
});
很酷不放纵 2024-12-07 09:40:14

我使用解决了类似的问题
Ext.ux.data.PagingMemoryProxy< /a>

效果很好
考虑到它不在 ExtJS 4 的标准版本中,您必须手动包含它

i solved a similar problem using the
Ext.ux.data.PagingMemoryProxy

which works pretty well
consider that it's not in the standart build of ExtJS 4, you have to manually include it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文