这是我的帖子,我在这个区域发布了分页的实际问题。 你可以从这个帖子中帮助我 森查论坛 sencha forum Ext Paging problem with EXt direct Grid panel
答案 0 :(得分:1)
最后我从论坛得到了答案
我的商店Js
var store = Ext.create('Ext.data.Store', {
model : 'Users',
remoteSort : true,
autoLoad : true,
pageSize: 5, // items per page
sorters : [{
property : 'name',
direction : 'ASC'
}],
proxy : {
type : 'direct',
directFn : 'Users.showAllUsers',
reader: {
root: 'users'
}
}
});
我的PHP功能
function showAllUsers($params)
{
$sort = $params->sort[0];
$field = $sort->property;
$direction = $sort->direction;
$start = $params->start;
$end = $params->limit;
($direction == 'ASC' ? 'ASC' : 'DESC');
$dbh = Dbconfig::dbconnect();
$stmt = $dbh->prepare("SELECT count(*) FROM users");
$stmt->execute();
$number_of_rows = $stmt->fetchColumn();
$sth = $dbh->prepare("SELECT * FROM users ORDER BY name $direction LIMIT $start,$end");
$sth->execute();
$dataAll = $sth->fetchAll();
$data = array(
"success" => mysql_errno() == 0,
"total" => $number_of_rows,
"users" => $dataAll
);
return $data;
}
答案 1 :(得分:0)
以下是有关商店和样本结果的示例,以便您的分页符合要求。
商店应如下所示
var myStore = Ext.create('Ext.data.Store', {
fields: [
{name: 'firstName', type: 'string'},
{name: 'lastName', type: 'string'}
],
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
root: 'records',
totalProperty: 'recordCount',
successProperty: 'success'
}
}
});
,服务器的结果应该是
{
recordCount: 63,
records: [
{
id: 944,
firstName: "Shannon",
lastName: "Joy"
},
{
id: 1819,
firstName: "Remi"
lastName: "Lucas"
},
.......
}