[英]Display a database table in a jqGrid
我拼命試圖在我創建的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>
有誰知道該怎么做?
萬一人們想知道答案,您必須:
網址:“ your_ajax_page.php ”
mtype:“ POST” //或GET
數據類型:“ json”
loadonce:“ true”
創建your_ajax_page.php並基本上在官方jqGrid演示網站(當前已關閉)上復制“ loadonce”演示。
鏈接數據庫數據和jqGrid行后,在頁面底部添加“ echo json_encode($ data_array) ”
應該是這樣,希望對您有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.