0
我做了一個演示,用jqGrid
表創建動態列,但遇到了一些問題。這是jqGrid的代碼片段:關於使用jgGrid創建動態列的問題
$.ajax(
{
type: "get",
url: "reports/providerList",
dataType: "json",
success: function(result)
{
var colNames = result.rows.colNames;
var colModels = result.rows.colModels;
$(grid_selector).jqGrid('GridUnload');
jQuery(grid_selector).jqGrid({
url: 'reports/getData',
datatype: 'json',
mtype: 'get',
colNames: colNames,
colModel: colModels,
viewrecords : true,
rownumbers:true,
rowNum:15,
rowList:[15,30],
pager : pager_selector,
altRows: true,
loadComplete : function() {
var table = this;
setTimeout(function(){
updatePagerIcons(table);
enableTooltips(table);
}, 0);
},
});
},
error: function(x, e)
{
alert(x.readyState + " "+ x.status +" "+ e.msg);
}
});
我的後端控制器:
@GetMapping("/providerList")
@ResponseBody
public Map<String, Object> providerList(@RequestParam(value = "rows", required = false) Integer pageSize, @RequestParam(value = "page", required = false) Integer pageNumber){
JQGridModel jqGridModel = new JQGridModel();
Map<String, Object> map = new HashedMap();
map.put("total", 4);
map.put("rows", jqGridModel);
map.put("records", 6);
return map;
}
@GetMapping("/getData")
@ResponseBody
public Map<String, Object> getData(){
List<ColData> colDatas = new ArrayList<>();
ColData colData1 = new ColData(2, "hello", new Date().toString(), "true", "admin");
ColData colData2 = new ColData(5, "say", new Date().toString(), "false", "pechen");
colDatas.add(colData1);
colDatas.add(colData2);
colDatas.add(colData2);
Map<String, Object> map = new HashedMap();
map.put("total", 4);
map.put("rows", colDatas);
map.put("records", 6);
return map;
}
在後端的數據格式:
public class JQGridModel {
private List<String> colNames;
private List<ColModel> colModels;
public JQGridModel() {
colNames = new ArrayList<>();
colNames.add("id");
colNames.add("name");
colNames.add("createTime");
colNames.add("status");
colNames.add("updateBy");
colModels = new ArrayList<>();
ColModel colModel1 = new ColModel("id", "id", 60f, false, false);
ColModel colModel2 = new ColModel("name", "index", 60f, false, false);
colModels.add(colModel1);
colModels.add(colModel2);
colModels.add(colModel2);
colModels.add(colModel2);
colModels.add(colModel2);
}
}
我注意到了在調試模式下點擊和/reports/getData
。怎麼回事,誰能幫忙?
謝謝,它確實是錯誤的原因,'name'應該與colData中'field'相同。 –
@DavePateral:不客氣! – Oleg