Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jqGrid Refreshing Local Data (JSON Object)

Tags:

jquery

jqgrid

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)
{
    $grid.jqGrid({
  data: results,
        datatype: "local",
        colNames:['#','File', 'Category', 'Line Number', 'Message Text','Detailed'],
        colModel:[
            {name:'count',index:'count', width:100, resizable: true},
            {name:'basename',index:'basename', width:100, resizable: true, classes:['basename']},
            {name:'category',index:'category', width:60, resizable: true},
            {name:'linenumber',index:'linenumber', width:60, resizable: true},
            {name:'text',index:'text',width:400, resizable: true},
            {name:'detailed',index:'detailed',width:100,classes:['detailed'], resizable: true }
            ],
        viewrecords: true,
     rowNum:100,
     rowList:[100,200],
     pager: '#debug_errors_pager',
     caption:"JSON Example"
 });
}

The data I'm passing in, results is an array of objects.

Issues:

1) The pager is totally off. It shows the correct count, but it doesn't actually let me page through the data.

2) I can't refresh the data. I'm using my own search function to arrive at my results. I can't figure out how to update the existing data. The grid initializes the first time. On subsequent attempts, it initializes to an empty table.

3) I've tried things like:

$grid.empty() - Doesn't work because the $grid object is decorated by jqgrid. I'm trying to "nuke" the old grid and simply re-render it as a workaround. `$grid.trigger('reloadGrid') - Doesn't work, don't know why.

Note: this is using jQGrid 3.7.

like image 529
Koobz Avatar asked Jun 05 '10 00:06

Koobz


2 Answers

You can use simple:

jQuery("#list")
    .jqGrid('setGridParam',
        { 
            datatype: 'local',
            data:mydata
        })
    .trigger("reloadGrid");
like image 125
Ved Avatar answered Oct 29 '22 06:10

Ved


I was able to achieve something similar. The trick for my issue was to clear out the data before updating the data grid parameter. Assuming your grid is initialized elsewhere (with datatype: 'local'), try:

function refreshGrid($grid, results) {
    $grid.jqGrid('clearGridData')
        .jqGrid('setGridParam', { data: results })
        .trigger('reloadGrid', [{ page: 1}]);
}
like image 25
Megan Avatar answered Oct 29 '22 06:10

Megan