2010-04-24 140 views
1

我正在使用jqGrid作爲我的數據表解決方案。以下是配置代碼。jqGrid未加載數據

$(function() { 
    $("#submitInput").click(function() { 
     alert("I am called...") 
     jQuery("#list").jqGrid({ 
      datatype: "json", 
      url: "http://localhost:1201/admin/someURL.htm", 
      mtype:"POST", 
      height: "auto", 
      colNames:["Column 1", "Column 2", "Column 3", "Column 4", "Column 5"], 
      colModel:[ 
       {name:"col1", index:"col1", sortable:true, resizable:false}, 
       {name:"col2", index:"col2", sortable:true}, 
       {name:"col3", index:"col3", sortable:false, resizable:false}, 
       {name:"col4", index:"col4", sortable:true, resizable:false}, 
       {name:"col5", index:"col5", sortable:true, resizable:false} 
      ], 
      sortname:'col1', 
      sortorder:'asc', 
      pager: $('#pager'), 
      rowNum:10, 
      viewrecords: true, 
      rowList:[10,20,30], 
      caption: 'Some Grid Values', 
      jsonReader: { 
       root: "responseData", 
       page: "currentPage", 
       total: "totalPages", 
       records: "totalFetchedRecords", 
       repeatitems: true, 
       cell: "rowContent", 
       id: "rowID" 
      }, 
      gridComplete: function() { 
       alert("Loading done..."); 
      } 
     }); 
    }); 
}); 

我的JSON數據以以下格式來:

"currentPage":"1","responseData":[ 
    {"rowContent":["Col1_Val_000001","Col2_Val_1","Col3_Val_1","Col4_Val_1","Col5_Val_1"],"rowID":"Col1_Val_000001"}, 
    {"rowContent":["Col1_Val_000002","Col2_Val_2","Col3_Val_2","Col4_Val_2","Col5_Val_2"],"rowID":"Col1_Val_000002"} 
], "totalFetchedRecords":"50","totalPages":"5"} 

在我的HTML,有ID爲 「submitInput」 和ID爲 「清單」 表格的按鈕。

不知何故,這些數據並未加載到網格中。是什麼原因?

回答

0

也許你應該不會創建jqGrid裏面的點擊句柄。您應該在以外點擊句柄並在處理程序內部調用jQuery("list").trigger('reloadGrid')。如果在開始時數據不應該加載到網格中,則可以使用datatype: 'local'作爲開始。如果需要,你可以使用div與jqGrid有時可以訪問,有時不可見使用hide()show() jQuery函數。在click處理程序的內部,您可以將datatype更改爲'json',然後撥打setGridParam(),然後致電trigger('reloadGrid')。在很多情況下,您還需要在調用trigger('reloadGrid')(參見Should one replace the usage addJSONData of jqGrid to the usage of setGridParam(), and trigger('reloadGrid')?)之前更改一些URL的參數,但可能您不需要它。