分页 很常用,在ext例子中,你按照上面例子 动态分页时往往不成功,我整理了一下,供大家分享:
page.js
Ext.onReady(function(){
var sm = new Ext.grid.CheckboxSelectionModel();
var cm = new Ext.grid.ColumnModel([
sm,
{header:"id",dataIndex:"id"},
{header:"name",dataIndex:"name"},
{header:"status",dataIndex:"status"},
{header:"category",dataIndex:"category"},
{header:"moviedate",dataIndex:"moviedate"},
{header:"actors",dataIndex:"actors"},
]);
cm.defaultSortable = true;
var ds = new Ext.data.Store({
url:"page.php",
reader: new Ext.data.JsonReader({
totalProperty: "totalProperty",
root: "results"
}, [
{name: "id",type:'int'},
'name','status','category','moviedate','actors'
])
});
var grid = new Ext.grid.GridPanel({
id:'testgrid',
renderTo:'grid-example',
ds: ds,
cm: cm,
sm: sm,
bbar: new Ext.PagingToolbar({
pageSize: 2,
store: ds,
displayInfo: true,
}),
autoWidth:true,
autoHeight: true
});
ds.load({params:{start:0,limit:2}});
});
page.php
<?php
//Not display warning,notice message
error_reporting(0);
//connect db
$link = mysql_pconnect("localhost", "root", "root")
or die("Could not connect");
mysql_select_db("test") or die("Could not select database");
//get count
$sql_count = "SELECT * FROM movie_info";
//get start and limit
$start = isset($_POST['start']) ? $_POST['start']:0;
$limit = isset($_POST['limit']) ? $_POST['limit']:10;
//generate sql
$sql = $sql_count . " LIMIT ".$start.", ".$limit ;
$rs_count = mysql_query($sql_count);
$rows = mysql_num_rows($rs_count);
$rs = mysql_query($sql);
while($obj = mysql_fetch_object($rs))
{
$arr[] = $obj;
}
//get result
echo '{"totalProperty":"'.$rows.'","results":'.json_encode($arr).'}';
分享到:
评论