有没有办法重新加载arraydata?

时间:2011-06-27 05:23:14

标签: jquery jqgrid


$(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"); });

我删除了网格中的数据,然后再次重新加载

怎么了?

1 个答案:

答案 0 :(得分:0)

首先,您不应在填充后立即清除关于clearGridData的网格数据(关于addRowData)。

如果在创建时填充jqGrid会更好。为此,您应该将mydata的定义移到网格创建之上,并将其他参数data: mydata添加到jqGrid。您应该再添加一个jqGrid参数gridview:true,以进一步提高性能。代码的所有其他部分(foraddRowDataclearGridDatasetGridParamreloadGrid)应该被删除。