$(document).ready(function(){
jQuery("#list2").jqGrid({
//url:"server.json",
datatype:'local',
//mtype:'GET',
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:55},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
height:230,
rowNum:10,
rowList:[10,20,30],
pager: '#pager2',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"Array Example"
});
var mydata = [
{id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"3",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"4",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"5",invdate:"2007-10-05",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"6",invdate:"2007-09-06",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"},
{id:"7",invdate:"2007-10-04",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"},
{id:"8",invdate:"2007-10-03",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"},
{id:"9",invdate:"2007-09-01",name:"test3",note:"note3",amount:"400.00",tax:"30.00",total:"430.00"}
];
for(var i=0;i<=mydata.length;i++)
jQuery("#list2").jqGrid('addRowData',i+1,mydata[i]);
$("#list2").jqGrid().clearGridData();
alert('reload');
jQuery("#list2").jqGrid().setGridParam({datatype: 'local'});
jQuery("#list2").trigger("reloadGrid");
});
I erased the data in the grid and then again it does not reload
What's wrong?
First of all you should not clear the grid data with respect of
clearGridDataimmediately after its filling (with respect ofaddRowData).If would be better to fill jqGrid at the time of creation. To do this you should move the definition of
mydataabove the grid creation and add additional parameterdata: mydatato the jqGrid. You should add one more jqGrid parametergridview:truewhich improve the performance additionally. All other parts of code (forwithaddRowData,clearGridData,setGridParamandreloadGrid) should be just removed.