代码:
Ext.onReady(function() {
var itemsPerPage = 2;
var store = Ext.create('Ext.data.Store', {
autoLoad: { start: 0, limit: itemsPerPage },
fields: ['id', 'name', 'age'],
pageSize: itemsPerPage,
proxy: {
type: 'ajax',
url: 'Handler1.ashx',
reader: {
type: 'json',
root: 'rows',
totalProperty: 'results'
}
}
});
var grid= Ext.create('Ext.grid.Panel', {
title: 'Paging',
renderTo: Ext.getBody(),
width: 400,
height: 350,
frame: true,
store: store,
forceFit: true,
columns: [
{ header: 'id', width: 30, dataIndex: 'id', sortable: true },
{ header: 'name', width: 80, dataIndex: 'name', sortable: true },
{ header: 'age', width: 80, dataIndex: 'age', sortable: true }
],
bbar: [
{
xtype: 'pagingtoolbar',
store: store,
displayInfo: true
}
]
});
store.load({ params: { start: 0, limit: 2} });
});
后台:
string sql = "select * from test";
string constr=ConfigurationManager.AppSettings["conn"];
DataTable dt = new DataTable();
using (SqlConnection conn = new SqlConnection(constr))
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
}
int total = dt.Rows.Count;
context.Response.Write(Dtb2Json(dt,total));
返回Json绝对没有问题。
其效果:
我一共6条数据,每页显示2条,但每次都是6条,请问大哥们,帮忙看看把,指点一下,谢谢