2010-04-24 138 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的参数,但可能您不需要它。