2017-09-01 57 views
0

我想加載與JSON數據網格和底部欄中的分頁。分頁工作與靜態,但不是動態數據

我的分頁正在加載,但不工作。同樣,這對靜態數據有效。

這是我撥弄靜態數據,Fiddle_Static 這是我撥弄靜態數據,Fiddle Dynamic 這裏是我的代碼。

var ItemsPerPage = 3; 

Ext.create('Ext.data.Store', { 
    storeId: 'Store', 
     proxy :{ 
     enablePaging: true, 
     type:'ajax', 
     url: 'data1.json', 
     reader:{ 
      type:'json', 
      rootProperty:"root" 
     } 
    }, 
    pageSize: ItemsPerPage, 
    autoLoad:true, 
    fields: ['Surname','Name','RollNo'] 
}); 

Ext.create('Ext.grid.Panel', { 
    title: 'Student', 
    store:Ext.data.StoreManager.lookup('Store'), 

    columns: 
[ 
    { text : 'SName' , dataIndex: 'Surname' ,width : 100}, 
    { text : 'Name' , dataIndex: 'Name' ,width : 100}, 
    { text : 'RNum' , dataIndex: 'RollNo' ,width : 100} 
], 
    width: 340, 
    height:250, 
    dockedItems: [{ 
     xtype:'pagingtoolbar', 
     store:'Store', 
     dock: 'bottom', 
     displayInfo:true 
     }], 
    renderTo: document.body 
}); 

任何人都可以請幫我解決這個問題。

+0

enablePaging是Ext.data.proxy.Memory的屬性,而不是Ext.data.proxy.Ajax。看看這個問題:https://stackoverflow.com/questions/31082315/locally-paging-on-extjs-5-store-of-type-ajax – RogerC

+0

[本地分頁的Extjs 5類型ajax商店]的可能重複( https://stackoverflow.com/questions/31082315/locally-paging-on-extjs-5-store-of-type-ajax) – RogerC

回答

-1

我想that's在線路
{ text : 'SName' , dataIndex: 'Surname' ,width : 100},
心不是一樣的表width: 340,

+0

它甚至是如何相關的。你能檢查一下小提琴手你在說什麼嗎? – David

+0

我查過了。我已將寬度:340,寬度:600,和文字:'SName',dataIndex:'姓',寬度:100}改爲'{text:'SName',dataIndex:'姓',寬度:200},'(對於每個)......並且對我有用。 –

+0

你能分享一下小提琴手嗎?我也改變了。沒有運氣的兄弟 – David

2

尋呼針對外部數據源的widht不工作原因width總和要求服務器只提供所要求的記錄。

當第一頁被加載到網格,存儲發送到服務器的請求:

data1.json?page=1&start=0&limit=3 

,並希望當用戶希望看到服務器與

success:true, 
total:27, 
data:[{Id:0},{Id:1},{Id:2}] (<-- three items only!) 

回答第2頁,客戶端然後發送到服務器的請求:

data1.json?page=2&start=3&limit=3 

並期望回答

success:true, 
total:27, 
data:[{Id:3},{Id:4},{Id:5}] (<-- three items only!) 

等等。

您的數據源現在正在返回所有項目,但客戶端只要求前三項。

要獲得小提琴動態數據源,你必須檢查「動態數據源」在data1.json的頂部,然後將標題改爲:

function(params, req, Fiddle) { 

現在你可以填寫函數體,例如快速和骯髒

if(params.page==1) 
return {"total":12, "root" : [{ 
    "Surname": "lisa", 
    "Name":"King", 
    "RollNo": 1 
    }, 
    { 
    "Surname": "John", 
    "Name":"Lever", 
    "RollNo": 2 
    }, 
    { 
    "Surname": "Lee", 
    "Name":"Dev", 
    "RollNo": 3 
    }]}; 
else if(params.page == 2) 
... 

如何在您的最終項目中做到這一點取決於你的後端如何看起來像。

+0

是的,完全理解需要發送到服務器的請求以及要獲取的內容。感謝您的解釋。但是我在這裏找到了如何將這些代碼放入我的ajax中。 – David

+0

@大衛我已經修改了我的答案。 – Alexander

+0

感謝這非常有幫助 – David