level 1
whkgiq
楼主
js代码如下:
Ext.onReady(function(){
var istore=Ext.create('Ext.data.Store',{
autoload:true,
fields:['id','uname','upwd'],
pageSize:5,
proxy:{
type:'ajax',
url:'test.php',
reader:{
type:'json',
totalProperty:'total',
root:'rows'
}
}
});
//Ext.Msg.alert('提示','提示这是一个测试');
Ext.create('Ext.grid.Panel',{
title:'Ext.toolbar.Paging',
renderTo:Ext.getBody(),
width:400,
height:150,
frame:true,
store:istore,
columns:[
{header:'id',width:50,dataIndex:'id',sortable:true},
{header:'用户名',width:100,dataIndex:'uname',sortable:true},
{header:'密 码',width:100,dataIndex:'upwd',sortable:true}
],
bbar:[{
xtype:'pagingtoolbar',
store:istore,
displayInfo:true
}]
});
});
test.php代码如下:
<?php
$limit=5;
$page=1;
$conn = mysqli_connect('localhost', 'root', '', 'books');
mysql_query("SET NAMES UTF8");
$sql = "select count(*) as num from user";
$countres = mysqli_query($conn, $sql);
$countattr = mysqli_fetch_assoc($countres);
$count = $countattr['num'];
if(!isset($_GET['id']))
{
$sql2 = "select id,uname,upwd from user limit ".(($page-1)*$limit).",$limit";
}
else{
$id = $_GET['id'];
$sql2 = "select * from user where id = '$id' limit ".(($page-1)*$limit).",$limit";
}
$rest = mysqli_query($conn, $sql2);
$attr['total'] = $count;
$rds = array();
while ($restattr = mysqli_fetch_row($rest)) {
$rds[] = $restattr;
}
$attr['rows'] = $rds;
//echo json_encode($b);exit;
$jsonstr = json_encode($attr);
echo $jsonstr;
?>
2017年03月03日 08点03分
1
Ext.onReady(function(){
var istore=Ext.create('Ext.data.Store',{
autoload:true,
fields:['id','uname','upwd'],
pageSize:5,
proxy:{
type:'ajax',
url:'test.php',
reader:{
type:'json',
totalProperty:'total',
root:'rows'
}
}
});
//Ext.Msg.alert('提示','提示这是一个测试');
Ext.create('Ext.grid.Panel',{
title:'Ext.toolbar.Paging',
renderTo:Ext.getBody(),
width:400,
height:150,
frame:true,
store:istore,
columns:[
{header:'id',width:50,dataIndex:'id',sortable:true},
{header:'用户名',width:100,dataIndex:'uname',sortable:true},
{header:'密 码',width:100,dataIndex:'upwd',sortable:true}
],
bbar:[{
xtype:'pagingtoolbar',
store:istore,
displayInfo:true
}]
});
});
test.php代码如下:
<?php
$limit=5;
$page=1;
$conn = mysqli_connect('localhost', 'root', '', 'books');
mysql_query("SET NAMES UTF8");
$sql = "select count(*) as num from user";
$countres = mysqli_query($conn, $sql);
$countattr = mysqli_fetch_assoc($countres);
$count = $countattr['num'];
if(!isset($_GET['id']))
{
$sql2 = "select id,uname,upwd from user limit ".(($page-1)*$limit).",$limit";
}
else{
$id = $_GET['id'];
$sql2 = "select * from user where id = '$id' limit ".(($page-1)*$limit).",$limit";
}
$rest = mysqli_query($conn, $sql2);
$attr['total'] = $count;
$rds = array();
while ($restattr = mysqli_fetch_row($rest)) {
$rds[] = $restattr;
}
$attr['rows'] = $rds;
//echo json_encode($b);exit;
$jsonstr = json_encode($attr);
echo $jsonstr;
?>
