我拼命想在我创建的jqGrid中显示数据库中的数据,但我真的不明白它是如何工作的。
我仔细阅读了有关jqGrid的文档,并尝试调整官方网站的演示,但我找不到用PHP / MySQL或AJAX脚本替换网格的“数据”选项的简单方法。这是我的代码:
<script>
$(function (){
$("#grid").jqGrid({
colNames: ["ID", "Context", "IP", "Community", "Modèle", "Uptime", "Version Soft", "Version Patch", "Date d'ajout", "Date modif", "Refresh"],
colModel: [
{name:'id', index:'id', width:60, sorttype:'int', align:'center'},
{name:'context', index:'context', width:130, align:'center'},
{name:'ip', index:'ip', width:150, align:'center'},
{name:'community', index:'community', width:100, align:'center'},
{name:'modele', index:'modele', width:80, align:'center'},
{name:'uptime', index:'uptime', width:150, align:'center'},
{name:'soft', index:'soft', width:150, align:'center'},
{name:'patch', index:'patch', width:150, align:'center'},
{name:'ajout', index:'ajout', width:100, sorttype:'date', align:'center'},
{name:'modif', index:'modif', width:100, sorttype:'date', align:'center'},
{name:'refresh', index:'refresh', width:70, align:'center', formatter:refresh_Button}
],
data: [
{id:"1",context:"LAB",ip:"192.168.xx.xx",community:"public",modele:"S57",ajout:"20-11-2017"}
],
caption: "Equipements disponibles :",
sortname: 'id',
sortorder:"desc",
rowNum:20,
rowList:[20,40,60],
pager:'#yolo'
});
function refresh_Button(cellvalue, options, rowobject){
return '<button type="button" onclick="">Go</button>';
}
});
</script>
</head>
<body>
<table id="grid"></table>
<div id="yolo"></div>
</body>
</html>
有谁知道怎么做这样的事情?
答案 0 :(得分:0)
万一人们想知道答案,你必须:
URL: “的 your_ajax_page.php ”
mtype:“POST”//或GET
数据类型: “JSON”
loadonce: “真”
创建 your_ajax_page.php 并基本上复制官方jqGrid演示网站(目前已关闭)的“loadonce”演示。
在链接数据库数据和jqGrid行之后,在页面底部添加“ echo json_encode($ data_array)”
这应该是它,希望它能帮到你