jqGrid setRowData method doesn't update hidden rows

前端 未结 1 1378
再見小時候
再見小時候 2020-12-18 16:06

I\'m using jqGrid\'s filterToolbar method to let users quick search/filter the grid data. I\'m using loadonce: true and datatype: local

相关标签:
1条回答
  • 2020-12-18 16:31

    You misunderstand how the grid are build. Grid can contain hidden columns, but no hidden rows. If one filter grid the full grid body will be removed and only the filtered rows will be inserted.

    The method setRowData can be used to modify any row of the grid, but you can't modify something which is not present in the grid.

    If you use local grid (datatype: 'local') then the data which you save in the grid will be saved in two internal jqGrid parameters data and _index. So you should modify the data object. To fill grid with modified data you need call .trigger("reloadGrid").

    So if you want modify columns item_id, item and item_cd of the grid's data for the rowid=2 you can do the following steps.

    1) Get references to the internal jqGrid parameters data and _index:

    var $myGrid = jQuery("#toolbar"),
        data = $myGrid.jqGrid('getGridParam', 'data'),
        index = $myGrid.jqGrid('getGridParam', '_index');
    

    2) Get reference to the object which represent the rowid which you need:

    var rowId = '2',
        itemIndex = index[rowId],
        rowItem = data[itemIndex];
    

    3) Modify the data item like you as need:

    rowItem.item_id = 2;
    rowItem.item = 'blargh';
    rowItem.item_cd = 12345678;
    

    4) Refresh grid contain (if needed) by reloading the grid

    $myGrid.trigger('reloadGrid');
    
    0 讨论(0)
提交回复
热议问题