简体   繁体   English

Ext JS Grid中的分页

[英]Pagination in Ext JS Grid

I have to create a grid with pagination. 我必须创建带有分页的网格。 The json data needed for the store will get in an ajax call. 存储所需的json数据将在ajax调用中获得。 Here I created store and it is loaded with the data returned from ajax call. 在这里,我创建了存储,并加载了从ajax调用返回的数据。 But the grid displaying all the data returned. 但是网格显示所有返回的数据。 I have to limit it into 5 for each page. 我必须将其限制为每页5个。

I tried the following code, 我尝试了以下代码,

      var store= new Ext.data.JsonStore({
        autoLoad    : {params: {start: 0, limit: 5}},
        totalProperty   : recordCount,
        sortInfo    : { field: "POS", direction: "ASC" },
        idProperty  : 'POS',
        data        : {},
        fields      : [
                        {'name' : 'POS'},
                        {'name' : 'NUM'}, 
                        {'name' : 'TIT'},
                        {'name' : 'MEN'},
                        {'name' : 'EIH'},
                        {'name' : 'WAE'},
                        {'name' : 'PRI'},
                        {'name' : 'LIF'}], 

    });

    var adrConn = $.getJSON('ajax.cfm', $.extend(test, {
        }), function(r) {   
            activeData = r.DATA;
            store.loadData(activeData);
            }
    );

    var grid = new Ext.grid.GridPanel({
          title         : '» test',
          applyTo       : 'panel',
          width         : 1000,
          loadMask      : false,
          autoHeight    : true,
          viewConfig    : {
                emptyText   : 'No data to display'
          },             
          tbar          : mainGridToolbar,
          bbar          : new Ext.PagingToolbar({
                  store         : store,
                  displayInfo   : true  
          }),
          store         : store,
          columns: [
                {header: "1", width : 50, dataIndex: 'POS', sortable: true},
                {header: "2", dataIndex: 'NUM', sortable: true},
                {header: "3", dataIndex: 'TIT', sortable: true},
                {header: "4", dataIndex: 'MEN', sortable: true},
                {header: "5", dataIndex: 'EIH', sortable: true},
                {header: "6", dataIndex: 'WAE', sortable: true},
                {header: "7", dataIndex: 'PRI', sortable: true},
                {header: "8", dataIndex: 'LIF', sortable: true}
          ]
      });

Any help is must appreciated...Thankyou 任何帮助都必须感谢...谢谢

By using PagingToolbar u can limit the grid size to 5 In that toolbar you can declare grid like this 通过使用PagingToolbar,您可以将网格大小限制为5。在该工具栏中,您可以像这样声明网格

 pageSize: 5,

Example for PagingToolbar is here ! 这里是PagingToolbar的示例!

Hope this helps you..... 希望这可以帮助您.....

You need to handle te pagination in your backend too. 您还需要在后端处理分页。 Thats probably the reason why you get all your records. 那可能就是您获得所有记录的原因。 ExtJS just sends the parameters to your backend and expect it will return the right records. ExtJS只是将参数发送到您的后端,并期望它将返回正确的记录。

In MySQL (offset = start, limit = limit, your page will be 1 here): 在MySQL中(偏移量=开始,限制=限制,您的页面在此处为1):

SELECT column FROM table
OFFSET 0 LIMIT 5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM