jqgrid reload grid partially working
Asked Answered
W

3

1

I have a client side managed jqgrid that I reload when some external event are fired. Everything is fine when I reload the grid with more data but when I reload it with less data, the amount of rows is incorrect.

For instance, when the is currently 100 rows in the grid and I reload it with 200, then the nav bar shows 200 records. If there are 200 rows in it and I refresh it with 25 rows , it still show 200 in the nav bar instead of 25. The code that refreshes the grid looks like:

 $("#list2").trigger("GridUnload");             
 $.ajax({
   url: 'http://xxx,
   dataType: 'json',
   async: false,
   success: function(data) {
              gridData = data;
          }

});

    $("#list2").setGridParam({ data: gridData });
    $("#list2").trigger("reloadGrid");

I don't think the problem is with the nav bar as I can clearly hit next page and see the addition rows.

Thanks

Whin answered 27/7, 2010 at 22:30 Comment(0)
R
4

Try to replace

$("#list2")[0].refreshIndex();
$("#list2").trigger("reloadGrid");

with

var g = $("#list2");
g.setGridParam({ data: gridData });
g[0].refreshIndex();
g.trigger("reloadGrid");

see http://www.trirand.com/blog/?page_id=393/help/losing-edited-cell-data-after-paging/ and http://www.trirand.com/blog/?page_id=393/bugs/data-parameter-are-not-modified-during-inline-editing/ for details.

In general you should use probably better set url parameter with respect of setGridParam methods or just use postData with a function (see How to filter the jqGrid data NOT using the built in search/filter box for details)

Reprobate answered 27/7, 2010 at 23:0 Comment(0)
L
3

I Solved this issue using this code but in my case issue was a bit different that newly added rows were not shown in JQGrid. So this code gets 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}]);
Lettielettish answered 26/2, 2014 at 11:44 Comment(0)
R
0

Same thing happened to me. My problem was in the PHP file that returns the data. You should verify that the conditions of the query that counts the records are equal to the conditions used to obtain the records. Probably the SQL statement to count records has no conditions. (Excuse my mistakes, I do not speak English)

Rankle answered 2/3, 2017 at 4:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.