简体   繁体   English

在Ext Grid中分页

[英]Paging in Ext Grid

Hi I am using Ext Js version 4.1.8 and I want to add paging on my extjs grid. 嗨,我正在使用Ext Js版本4.1.8,我想在extjs网格上添加分页。

I have been using 我一直在用

Ext.create('Ext.data.Store', {
    model: 'List',    
    proxy:{
       type: 'ajax',
       api:{
           read:'getJson.php',
       },
       extraParams:{
           PRKEY : selectedProjId
       },
    },
    reader:{
       type: 'json',
       root: 'data',    
    }
});

That is working fine, but if I change my json format in my php file and change the root type to someother string like 'users' I do not see any data 效果很好,但是如果我在php文件中更改json格式并将根类型更改为其他字符串(例如“用户”),则看不到任何数据

Here is my json creation code in getJson.php 这是getJson.php中我的json创建代码

//in a loop
$aNode = array( 
    "Name" => "My Name",
    "ID"   => "123");
array_push($nodeArr, $aNode);
//end of loop

$json = new Services_JSON;
echo $json->encode($nodeArr);

and here is for the php code I want to run 这是我要运行的php代码

//in a loop
$aNode = array( 
"Name" => "My Name",
    "ID"   => "123");
array_push($nodeArr, $aNode);
//end of loop

$json = new Services_JSON;
$jsonResult = array(
    'success' => "true",
    'users' => $nodeArr
);
echo $json->encode($jsonResult );

and here is the new store code 这是新的商店代码

Ext.create('Ext.data.Store', {
    model: 'List',  
    proxy:{
        type: 'ajax',
        api:{
            read:'getJson.php',
        },
        extraParams:{
            PRKEY :selectedProjId
        },
    },
    reader:{
        type: 'json',
        root: 'users'
    }
});

Please help so I can add totalProperty in reader of my store and perform paging. 请帮忙,以便我可以在商店的阅读器中添加totalProperty并执行分页。

Add the value of totalProperty adjacent to success, for example: 在成功旁边添加totalProperty的值,例如:

$total = get_total_number_of_records();
$jsonResult = array(
    'success' => "true",
    'total' => $total
    'users' => $nodeArr
);

Server side has to honor sent start and limit parameters in addition to total and it has to return only limit number of records starting from start , not all from the database. 服务器端除了要遵守total之外,还必须遵守发送的startlimit参数,并且它必须仅返回从start limit记录数,而不是从数据库中返回的所有记录数。

ahh figured it out guys. 啊,想通了。 I was using 'reader' outside proxy block. 我在代理块外使用“阅读器”。 I changed it and added it inside proxy and it worked. 我对其进行了更改并将其添加到代理服务器中,并且它可以正常工作。

Cheers! 干杯! here is how it works 下面是它的工作原理

Ext.create('Ext.data.Store', {
    model: 'List',  
    proxy:{
        type: 'ajax',
        api:{
            read:'getJson.php',
        },
        extraParams:{
            PRKEY :selectedProjId
        },
        reader:{
            type: 'json',
            root: 'users'
        }
    }        
});

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

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