jqGrid Refreshing Local Data (JSON Object)

前端 未结 6 1721
走了就别回头了
走了就别回头了 2021-01-31 18:44

I\'m trying to use jqGrid with local data and I\'m finding a couple of issues:

I\'m initializing the thing like so:

function refreshGrid($grid, results)
         


        
6条回答
  •  [愿得一人]
    2021-01-31 19:13

    Following works for me when refreshing data on an existing grid:

    var gridData = [...];
    
    var grid = jQuery('#gridId');
    grid.jqGrid('clearGridData');
    if( grid.get(0).p.treeGrid ) {
        grid.get(0).addJSONData({
            total: 1,
            page: 1,
            records: gridData.length,
            rows: gridData
        });
    }
    else {
        grid.jqGrid('setGridParam', {
            datatype: 'local',
            data: gridData,
            rowNum: gridData.length
        });
    }
    grid.trigger('reloadGrid');
    

    I had to do it this way because reloadGrid() calls populate(), populate() calls addLocalData() and passes the return value to addJSONData(), but for treeGrid == true, addLocalData() returns nothing, and addJSONData() subsequently does nothing.

提交回复
热议问题