2017-09-01 62 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