0

What Is the proper way to add a row to jqGrid? If I call this:

$('#quoteGrid').jqGrid('addRowData', undefined /* random row id */, rowData);

The row appears in the grid, however, if I call this at any point after:

$('#quoteGrid').trigger('reloadGrid');

The row is gone. I've checked firebug and the data is actually being added to the array, but it gets removed when the reloadgrid is called.

My grid data parameters:

    datatype: 'local',
    data: data,
    loadonce:true,
mechanical_meat
  • 163,903
  • 24
  • 228
  • 223
Bcbury
  • 117
  • 1
  • 9
  • He isn't fetching from the server, his datatype is `'local'`, see my answer below. – Mark Jan 25 '13 at 18:53
  • I'd prefer not to make a database call for every row that's added. :) – Bcbury Jan 25 '13 at 19:04
  • Well you need to let something know that you are adding a record to the dataset....how did you plan to handle that? – Mark Jan 25 '13 at 19:07
  • getting the data after it's all added, and then saving to the DB – Bcbury Jan 25 '13 at 19:39
  • Doesn't sound impossible, but sounds overly complicated unless there is a reason driving this? – Mark Jan 25 '13 at 19:44
  • Generating quotes for customers, and adding items to a jqgrid table, unless there's an existing quote, the only db call is to get the item data used to populate the row with. – Bcbury Jan 25 '13 at 20:07
  • You are going to have to store the data then in the client side...where you then have to worry about timeouts, client manipulation of the data, or in a session, and session time outs, etc. Did my answer below get you going? – Mark Jan 25 '13 at 20:10
  • It totally pointed me in the right direction, however, I can't upvote because I don't have enough rep :) – Bcbury Jan 25 '13 at 20:49
  • Marking it as the correct answer is enough :) – Mark Jan 25 '13 at 20:54

3 Answers3

1

It is being added to the grid but not to your local object that is storing the data that is presented in your grid. You can hook up something in your addRowData function call to append it to your local data store and then it will show up the next time your grid looks to that object to reload it's data.

Mark
  • 3,123
  • 4
  • 20
  • 31
  • Doesn't seem to work. I pulled the array data out using the 'getGridParam' function, added the row, then pushed it back using 'setGridParam'. After reloading the grid, the data is still in the 'data' object of the grid, just not being displayed. – Bcbury Jan 25 '13 at 19:13
  • Try with `loadonce: false` – Mark Jan 25 '13 at 19:16
  • Still kills the added item. added item is still in the data object. Our company just bought commercial support from them, gonna see why this happens – Bcbury Jan 25 '13 at 20:12
  • If you can produce a JSFiddle of this I would be happy to have a look, I'm half curious myself. – Mark Jan 25 '13 at 20:17
  • So, Evidently, if grouping is turned on, and the group for the item is undefined, it will keep it in the dataset, but not display it if the grid is reloaded. This isn't stated in the documentation: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:grouping – Bcbury Jan 25 '13 at 20:42
1

I Solved this issue using this code. This code gets executed after adding row, i get the Updated data for Grid and then save it in local object and then reassign this local object to grid and reload grid to page 1.

        var grid_data = $("#Grid_ID").jqGrid('getGridParam', 'data'); 
        $("#Grid_ID").jqGrid('clearGridData').jqGrid('setGridParam', { 
            datatype: 'local',
            data: grid_data,
            rowNum: grid_data.length 
        }).trigger('reloadGrid', [{ page: 1}]);
Uzair Bin Nisar
  • 675
  • 5
  • 7
-1

I was trying Uzair's solution, but $("#Grid_ID").jqGrid('getGridParam', 'data') was resulting in the deleted row (grid with two rows), what I had to do was to use $("#Grid_ID").jqGrid('getRowData'); instead. Hope it helps.

Liam
  • 27,717
  • 28
  • 128
  • 190