jqGrid paging question
Asked Answered
C

1

8

If you have 17 records and are displaying 15 at a time then when you're on page 2 you see records 16-17 of 17 - makes sense.

Now when you're on this second page and you hit the reload button on the nav (set datatype='json') when the grid reloads the nav is showing that the grid is displaying 16-30 of 17. This seems to be a bug - is there a workaround?

The grid still has 17 rows - but it's trying to show a full 15 rows (the rowNum) setting on the second page when it should only be showing two rows (16-17). And the nav pagination text is incorrect (referring to 30 rows when there is only 17).

Carmeliacarmelina answered 27/9, 2010 at 20:33 Comment(0)
C
29

You are right. It is an old problem. I used always before

$("#list").setGridParam({page:1}).trigger('reloadGrid');

but there is another way. The trigger 'reloadGrid' support additional options: 'current' and 'page'.

$("#list").trigger("reloadGrid", [{page:1}]);

will reset page to 1 in one step. The usage in the form

$("#list").trigger("reloadGrid", [{current:true}]);

allows to preserver current selection. You can of cause combine both options.

Colpin answered 27/9, 2010 at 21:24 Comment(20)
Are any of these options a workaround for the bug? That is in my example, can I reload the grid and be on page 2 where the grid will show just records 16-17 ?Carmeliacarmelina
And has this bug been reported?Carmeliacarmelina
@Marcus: Yes on both your questions. You can directly start with page 2 if you set it in the jqGrid parameters. You can report the bug yourself or I can do this. Currently I want make a short pause, but stay too longer on the stackoverflow. I have to continue my main work... :-). By the way there are currently only the two options: page and current.Colpin
@Marcus: I think that the reseting of page always to 1 can not be implemented. Sometimes you need refresh the current page (click 'refresh' button on the navigator). In the case the pager should stay unchanged. If you go to the next page, the reload will be also started. So it is not a bug. You should just take in consideration to reset page to 1 if it needed. For example if you change url or the postData parameters before you should 'reloadGrid' you should also change the page parameter. One more short information to you: I appended your bug report about onPager.Colpin
Issue is if you're on page 2 - and you are showing records 16-17 of 17 and you STAY on the same page and reload - now you are viewing records a totally different set of records - this doesn't make sense from a UI perspective. After reloading you should still see the same two records - just updated. But what you see is 15 records.Carmeliacarmelina
@Marcus: I don't understand why it should like you describe. The server will receive the request with page=2 and will get the same two rows. Which value of page you see send over the wire?Colpin
Server does get page=2. Grid is using loadOnce=true so server is returning all rows. In the server response you get records=17, page=2, total=2 and then 17 row items. jqGrid correctly says we are on page 2 but it is a) showing 15 items instead of the 2 and b) the paging description is incorrect - "displaying 16-30 of 17" - this is obviously all wrong as we only have 17 rows, not 30. So to summarize the data in the grid is correct but jqGrid is displaying the wrong slice of data on page 2 and the paging description is incorrect.Carmeliacarmelina
@Marcus: We are speaking a lot of time about two different things. Why you don't write before that you use loadonce:true? You wrote only about datatype:'json'. If you has loadonce:true you has only short time datatype:'json' and the rest of time you work with datatype:'local'! We just spend our time. The loadonce:true is design to hold all the data locally. So in your case if you change datatype:'json' back before reload and want do see the same page which was before reload started you have to change page inside of setTimeout called in loadComplete.Colpin
@Marcus: See #3565398. As a demo see ok-soft-gmbh.com/jqGrid/DataToMultiSelect.htm and ok-soft-gmbh.com/jqGrid/DataToSelect.htm. Then do a little other things abd get information from the userData, but the idea is the same. You can hold the information which you need in a locan variables.Colpin
In your example why does getGridParam('page') always equal 1? If you're on page 2 and you hit reload in the nav, then getGridParam('page') will equal 2. So not sure why you have to bother keeping track of the page number and setting the page number in loadComplete.Carmeliacarmelina
@Marcus: I don't understand what you mean and with what exactly example. I select data and set page number in loadComplete because I can do this after the data are loaded from the server as JSON per ajax.Colpin
In the examples on your website and SO post you have ` var curPage = jQuery("#list").getGridParam('page'); // is always 1` Why is it always 1? If you reload (using the nav) when you are on page 2 then getGridParam('page') will already be 2 if you don't explicitly reset it to 1 prior to reload.Carmeliacarmelina
Well I tried the examples you mentioned. It works. But the screen flickrs on the load as we are using setTimeout() to run the reload in loadComplete. So the grid loads on page 1, then reloads in 100 ms on page N. It works but you can see the grid flickr. I tried not using setTimeout() but the grid doesn't seem to move to the new page properly.Carmeliacarmelina
@Marcus: Now I understand what you mean. curPage will be always 1 because it will be get inside of if (jQuery("#list").getGridParam('datatype') === "json"). So it will be exacuted only at the load of data from the server and not at the next local reloads. So after the grid will be reloaded locally after trigger("reloadGrid"). At all next paging or click "Reload" buton of Navigar the code will be not executed. The example is an answer to the question how make initial data selection of data loaded from the server per ajax anad loadonce:true.Colpin
@Marcus: Of cause the grid flickrs a little at every reload, but it works. For me it is not a real problem Do you have a bettr suggestion which also worked and has flickrs?Colpin
Thanks Oleg. Not sure I'm going ot use that solution because of the flickering.. wish there was a way to do a reload from the nav without the flicker..Carmeliacarmelina
@Markus: It reminds me of a beggar, who is unhappy while he became only $100 and no new BMW. Just reread your original question and count which comment we are written. Do you know a better solution of your problem? Do you want a new BMW for no money? Do you know a better grid as jqGrid? How much you payed for this? Do you can write a better grid for no money and give it other people?... Then just be happy from the things which you have. It is not a little by the way...Colpin
Fair enough Oleg. jqGrid is awesome and so is your support!Carmeliacarmelina
Thanks a lot for the solution. It helped me a lot to resolve the issue :).Jaundice
@jonatanes: You are welcome! If you use free jqGrid fork, which I develop, then the answer and [another one]()https://mcmap.net/q/469722/-how-to-get-jqgrid-reload-to-go-to-server could be helpful too. It describes fromServer option, which is helpful to reload the data from the server in case if you use loadonce: true option.Colpin

© 2022 - 2024 — McMap. All rights reserved.