flexigrid json 格式
默认的 json 数据格式 new string[]{"1","2","3"}
有木有办法扩展 让其和列名对应么,
------解决方案--------------------
您用的是最初的flexigrid 给你个重写过的http://download.csdn.net/detail/qq307023807/4300321
json格式是
$json = "";
$json .= "{";
$json .= "\"page\":$page,";
$json .= "\"total\":$total,";
$json .= "\"rows\":[";
$rc = false;
while ($row = mysql_fetch_array($result)) {
$status = ($row['status']==0)?"不显示":"显示";
if ($rc) $json .= ",";
$json .= "{";
$json .= "\"id\":\"".$row['ID']."\"";
$json .= ",\"position\":\"".addslashes($row['position'])."\"";
$json .= ",\"title\":\"".addslashes($row['title'])."\"";
$json .= ",\"addtime\":\"".addslashes($row['addtime'])."\"";
$json .= ",\"status\":\"".addslashes($status)."\"";
$json .= ",\"pic\":\"".addslashes("<img id=pic width=80px src=$row[pic]>")."\"";
$json .= ",\"linkurl\":\"".addslashes($row['linkurl'])."\"";
$json .= ",\"script\":\"".addslashes(urlencode($row['script']))."\"";
$json .= "}";
$rc = true;
}
$json .= "]";
$json .= ",\"position\":\"".$position."\"";
$json .= "}";
前台调用
var p = {
url: 'adv.php?position='+encodeURI(position),
method:'get',
dataType: 'json',
colModel : [
{display: 'id', name : 'id', width : 10, sortable : true, align: 'center',hide:true},
{display: '位置', name : 'position', width : 110, sortable : true, align: 'left'},
{display: '标题', name : 'title', width : 130, sortable : true, align: 'left'},
{display: '添加时间', name : 'addtime', width : 110, sortable : true, align: 'left'},
{display: '状态', name : 'status', width : 30, sortable : true, align: 'left'},
{display: '图片', name : 'pic', width : 100, sortable : true, align: 'left'},
{display: '图片链接', name : 'linkurl', width : 190, sortable : true, align: 'left'},
{display: '内容', name : 'script', width : 900, sortable : true, align: 'left',hide:true}
],
buttons : [
{name: '添加', bclass: '', onpress : opreateAdv},
{name: '修改', bclass: '', onpress : opreateAdv},
{name: '删除', bclass: '', onpress : opreateAdv}
],
searchitems : [
{display: '标题', name : 'title'},
{display: '位置', name : 'position'}
],
sortname: "addtime",
sortorder: "desc",
usepager: true,
title: title,
useRp: true,
checkbox:true,
showTableToggleBtn: true,
rp: 5,
width: 900,
height: 600
//rowhandler: contextmenu,//是否启用行的扩展事情功能,在生成行时绑定事件,如双击,右键菜单等
//onrowchecked: callme
}
$("#flex1").flexigrid(p);