不好意思,我是剛學Ext的新手~不太懂...
這是我js代碼
/**
- @example Paging Toolbar *
- This example demonstrates loading data in pages dynamically from the server using a {@link Ext.toolbar.Paging Paging Toolbar}.
- Note, that since there is no back end (data is loaded from a static file at
data/users.json
) each page will show the same data set. */ Ext.require('Ext.data.Store'); Ext.require('Ext.grid.Panel'); Ext.require('Ext.toolbar.Paging');
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [ 'name', 'email', 'phone' ]
});
Ext.onReady(function() {
var userStore = Ext.create('Ext.data.Store', {
model: 'User',
autoLoad: true,
pageSize: 4,
proxy: {
type: 'ajax',
url : 'data/users.json',
reader: {
type: 'json',
root: 'users',
totalProperty: 'total'
}
}
});
// specify segment of data you want to load using params,這邊是我看到網路上的,自己加的,想要讓他數據變得一樣
userStore.load({
params:{
start:0,
limit: 4
}
});
Ext.create('Ext.grid.Panel', {
renderTo: Ext.getBody(),
store: userStore,
width: 400,
height: 200,
title: 'Application Users',
columns: [
{
text: 'Name',
width: 100,
dataIndex: 'name'
},
{
text: 'Email Address',
width: 150,
dataIndex: 'email'
},
{
text: 'Phone Number',
flex: 1,
dataIndex: 'phone'
}
],
dockedItems: [{
xtype: 'pagingtoolbar',
store: userStore, // same store GridPanel is using
dock: 'bottom',
displayInfo: true
}]
});
});
這是我的json代碼
{
"success": true,
"total": 12,
"users": [
{ "name": "Lisa", "email": "lisa@simpsons.com", "phone": "555-111-1224" },
{ "name": "Bart", "email": "bart@simpsons.com", "phone": "555-222-1234" },
{ "name": "Homer", "email": "home@simpsons.com", "phone": "555-222-1244" },
{ "name": "Marge", "email": "marge@simpsons.com", "phone": "555-222-1254" }
]
}
我想問說為什麼得到的結果是這樣的http://docs.sencha.com/ext-js/4-0/guides/grid/examples/paging_toolbar/index.html
分頁後數據都一樣,我覺得有點疑惑...
因為我的json數據只有4筆,我想要每頁2筆且第一頁為Lisa和Bart第二頁為Homer和Merge的話跟怎麼改?
謝謝大家~ :)