Reputation: 1826
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?
Upvotes: 2
Views: 4428
Reputation: 1002
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
Upvotes: 0
Reputation: 935
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
}]
});
});
Upvotes: 2