Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_Related Related Topics sp_TopicIcon
sortGrid breaking pagination?
18/05/2014
02:16
Avatar
dmittner
Member
Members
Forum Posts: 4
Member Since:
18/05/2014
sp_UserOfflineSmall Offline

So one problem lead to a solution that ended up causing another problem...

Problem #1:

My columns can vary from load to load so I hide/show them accordingly, but also adjust the sorting to a column that's valid on the backend. So if the previously sorted column no longer applies, a new one is chosen. However, jqGrid doesn't look for sorting variables in responses for the column header visuals to update.

Solution:

Within loadComplete I do: grid.jqGrid('sortGrid', data.sortBy, false, data.sortOrder.toLowerCase());

Obviously I don't want to unnecessarily loop things, so a reload isn't performed as part of this command.

Problem #2 (and bug):

Now what's happening is that the typical pagination controls aren't working. It won't advance beyond page 2. If I had to guess I'd say that the sortGrid method causes an internal page variable to reset to page 1. So while the visual still shows page 2, an attempt to move forward one page or backwards doesn't work because it thinks it's on page 1 already.

Thus, these work:

  • Manually entering a page number / hitting enter
  • Using the arrow control to go directly to the last page

And these don't:

  • Incrementing up one page
  • Decrementing down one page
  • Going directly to the first page

All those behaviors make sense if you assume the logic thinks it's already on page one, which I'd put forth is the bug.

19/05/2014
14:03
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

The idea to call sortGrid in loadComplete event is very dangerous. You will go to infity loop.

The reason for this is that sorGrid call again populate . When you populate you call loadComplete, which call again sortGrid and so on.

I think the best idea for this purpose is to use setGridParam to change the sortname parameter and sortorder one.

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

19/05/2014
18:43
Avatar
dmittner
Member
Members
Forum Posts: 4
Member Since:
18/05/2014
sp_UserOfflineSmall Offline

The idea to call sortGrid in loadComplete event is very dangerous. You will go to infity loop.

No it won't. The second parameter is whether you want it to initiate a reload. I specifically mentioned above that I use this to avoid an infinite loop.

I think the best idea for this purpose is to use setGridParam to change the sortname parameter and sortorder one.

Been there, tried that. setGridParam doesn't initiate any visual change to the column headers, which is what I'm trying to solve.

20/05/2014
12:15
Avatar
admin
Admin
Members
Forum Posts: 66
Member Since:
05/05/2007
sp_UserOfflineSmall Offline

Hello,

Can you please post a simple demostration?

Thank you

Kind Regards

20/05/2014
20:51
Avatar
dmittner
Member
Members
Forum Posts: 4
Member Since:
18/05/2014
sp_UserOfflineSmall Offline

Here's a jsFiddle with an example of the problem.

http://jsfiddle.net/Jq2HR/

In making that I learned that the issue only exists when sortGrid is executed within the loadComplete event handler. If it's executed separately then subequent navigation works fine. So whatever is happening that's messing up the behavior must be running internally after the loadComplete event fires, but since that's the last event in the data loading process, there's no option for me to execute sortGrid any later.

The only remaining option I can think of would be to set a timeout in loadComplete to execute sortGrid after jqGrid is finished doing whatever it does after that event. Seeing as though I'm just trying to fix a subtle visual this is a possibility, but might fall out of sync if a user paginates quickly, so clearly not ideal.

IMO the best solution would be for jqGrid to support server-side sorting defining. So if the server provides sort/order variables (or whatever is defined in prmNames) in the response, those will automatically overwrite whatever jqGrid already thinks sorting is. The server being the authorative source over how the data is actually sorted, it makes sense that it could tell jqGrid that for proper presenation. I actually expected this behavior to exist already and have returned sorting information this whole time...

22/05/2014
14:38
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

The reload parameter if set to false does not reload the grid only if you are in the same sortname and same sortorder - this mean is your current grid setting is : column1 and the sortorder is asc, the grid will not be reloaded only if you

$('#grid').jqGrid('sortGrid','column1',false,'asc');

In all other cases you will got with reloading.
Please look here

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
71 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

OlegK: 1255

markw65: 179

kobruleht: 144

phicarre: 132

YamilBracho: 124

Renso: 118

Member Stats:

Guest Posters: 447

Members: 11373

Moderators: 2

Admins: 1

Forum Stats:

Groups: 1

Forums: 8

Topics: 10592

Posts: 31289

Newest Members:

, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information