The Rows are shown in HTML. But jqgrid doesnot show the rows. Have even tried adding row one by one instead. But didnt help. I am new to JQgrid. I am just trying these things in my code based on the examples on the internet. I am totally unable to understand what is going wrong here.
This is my jquery code
$("#tblStateTableData").jqGrid({ datatype: 'local', width: 800, //specify width; optional colNames:['State Code','State Name', 'Active Y/N'], //define column names colModel:[ {name:'id', index:'id', key: true, width:100, hidden:false}, {name:'stateNm', index:'stateNm', width:150, hidden:false}, {name:'activeYn', index:'activeYn', width:100, edittype:"checkbox", hidden:false} ], //define column models pager: '#pager', //set your pager div id rowNum:10, sortname: 'id', //the column according to which data is to be sorted; //optional viewrecords: true, //if true, displays the total number of records, etc. //as: "View X to Y out of Z” optional sortorder: "asc", //sort order; optional }); function getCountryCode() { var countryCd = $('#txtCountry').val(); $("#txtCountryCd").val(countryCd); if (countryCd != "") { $.post("getStateTableList.html",{ "countryCd" : countryCd },function(data) { data = $.parseJSON(data); if (data.status == "success") { var stateTableList = data.stateTableList; $('#tblStateTableData').jqGrid('setGridParam', {datatype:"jsonstring" ,datastr:stateTableList}).trigger('reloadGrid'); } }); } }
The JSON Returned from Java Code is as follows
"{"page":"1","records":7,"rows":[{"cell":["MELBOURNE","Y"],"id":1},{"cell":["NEW SOUTH WALES","Y"],"id":7},{"cell":["QUEENSLAND","Y"],"id":6},{"cell":["SOUTH AUSTRALIA","Y"],"id":3},{"cell":["TASMANIA","Y"],"id":5},{"cell": ["VICTORIA","Y"],"id":4},{"cell":["WESTERN AUSTRALIA","Y"],"id":2}],"total":"1"}"
And here is Java Code
JqgridModel grid = new JqgridModel(); grid.setPage("1"); grid.setRecords(stateListObj.size()); grid.setTotal("1"); List rows = new ArrayList<>(); for (EppsStateMst eppsStateMst : stateListObj) { JQGridRow row = new JQGridRow(); row.setId(eppsStateMst.getId().getStateCd()); List cells = new ArrayList(); cells.add(eppsStateMst.getStateNm()); cells.add(eppsStateMst.getActiveYn()); row.setCell(cells); rows.add(row); } grid.setRows(rows); JSONSerializer serializer = new JSONSerializer(); String jsonResult = serializer.exclude("*.class").deepSerialize(grid); json.addProperty("status", "success"); json.addProperty("stateTableList", jsonResult); return json.toString();