php:
while($row = mysql_fetch_array($result))
{
$res[$i]['oid']=$row['oid'];
$res[$i]['uname']=$row['uname'];
$res[$i]['odate']=$row['odate'];
$res[$i]['oispro']=$row['oispro'];
$res[$i]['gid']=$row['gid'];
$i++;
}
echo json_encode($res);
js:
$.post(
'../php/loadOrderData.php',
{},
function(res) {
$("#circular-loading").addClass('hidden');
drawTable1(res);
}
);
function drawTable(res){
var store = new Ext.data.JsonStore({fields:[ 'oid', 'uname', 'odate' ],
data:$.parseJSON(res)
});
console.log('res',res);
console.log('res1',$.parseJSON(res));
var columns = new Ext.grid.ColumnModel({
columns:[
{ header:'订单编号', dataIndex:'oid', width:100,sortable:true},
{ header:'商品名称', dataIndex:'uname', width:100,sortable:true },
{ header:'购买时间', dataIndex:'odate', width:100,sortable:true}
]
});
var grid = new Ext.grid.GridPanel({
title:'GridPanel',
width:680,
height:200,
store:store,
viewConfig:{
forceFit:true
},
colModel:columns,
tools:[
{id:'close',qtip:'关闭'},
{id:'refresh',qtip:'刷新'},
]
});
grid.render('columns');
}
采用直接方式
var store = new Ext.data.JsonStore({
fields:[ 'oid', 'uname', 'odate' ],
url:'../php/loadOrderData.php',
remoteSort:true
});不行
本文介绍了一个使用PHP从数据库获取数据并使用JavaScript处理这些数据以填充ExtJS GridPanel的示例。PHP脚本通过MySQL查询获取订单数据,然后使用JSON格式返回给JavaScript。JavaScript接收到数据后解析JSON,并利用ExtJS库创建一个动态表格。
387

被折叠的 条评论
为什么被折叠?



