[英]populate jqgrid with json data from a PHP file
我對trirand的jqGrid絕對陌生。 我有一個基本的問題。 我有一個形式,它調用一個php文件,后者在提交按鈕后回顯JSON響應。 我可以按照手冊中提到的jqGrid所需的格式來格式化JSON數據。 但是,如何在不使用其他按鈕的情況下填充它。 我努力了:
$("#output_grid").jqGrid({ //grid5 function starts
url: "searchresults.php",
datatype: "json",
mtype: "GET",
................
................
我的意思是如何觸發網格以讀取php文件發送的數據?
function start_post_data(){
$.post(
'script.php',
{ a : 1,
b : 2
},
start_get_data_ajax,
'json'
);
}
function start_post_data_ajax(data, statusText, xhr){
// add the data to the grid
$("#selectieatable").jqGrid("clearGridData", true).trigger("reloadGrid");
i=0;
$.each(data['rows'], function(key, val) {
jQuery("#selectieatable").jqGrid('addRowData',i+1,data['rows'][key]);
i++;
})
}
收到如下所示的搜索結果后,嘗試觸發reloadGrid
事件:
$('#output_grid').jqGrid('clearGridData'); // Remove previous data
$('#output_grid').jqGrid({
url: 'searchresults.php',
datatype: 'json',
...
}).trigger('reloadGrid', [{ page: 1 }]); // Reload Grid, and start showing page 1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.