jQWidgets Forums
jQuery UI Widgets › Forums › Grid › Save status with sortmode=many
This topic contains 4 replies, has 3 voices, and was last updated by jurgz 1 year, 11 months ago.
-
Author
-
HI,
I have a grid with the ability to sort by multiple columns.
Every time a sorting is done it saves the state in the database.In this way the user has the possibility to customize the visualization of the grids.
However, reloading the grid via the saved state, I notice that it only saves the last column I sorted and not all.
It is therefore possible to save the sorting status in several columns.
I tried going a different round, saving these sorted columns. When the grid is loaded, I apply the filters, but one at a time and this means that, if I have four filters, 4 different queries are made.
Thank you
MarcoHi,
When you get the state, you can invoke the getsortinformation method to get the full sorting info, then merge it with the state and save it to desired place.
I hope this helps!
Best regards,
Svetoslav BorislavovjQWidgets Team
https://www.jqwidgets.com/HI,
Thanks for the reply.Yes, to save it’s no problem, I already use the getsortinformation function.
My problem is that when I recover the state that I have saved in the database, the json that is saved does not contain the information of all the sorts.
Then, as you said, I save the information via getsortinformation in another field.
When I reload the grid I load the saved state first and then apply the sorts.
So if I sorted by 4 columns col1, col2, col3, col4 after loading state I have to do:
elm.jqxGrid(‘sortby’, ‘col1’ ‘asc’);
elm.jqxGrid(‘sortby’, ‘col2’ ‘asc’);
elm.jqxGrid(‘sortby’, ‘col3’ ‘asc’);
elm.jqxGrid(‘sortby’, ‘col4’ ‘asc’);This works but each “sortby” launches a different query.
So to load the data of the same query I have total 5 queries.Is there another way?
Thank you
MarcoHi Marco,
To minimize the requests you can create an “updating” global variable. When updating multiple columns set it to true. Then in the dataAdapter, check if it is true before making the request. Here is an example:
The sort will not execute if updating is truevar source = { datatype: "array", localdata: {}, totalrecords: 1000000, sort: function () { if(updating){return;} // update the grid and send a request to the server. $("#jqxgrid").jqxGrid('updatebounddata', 'sort'); } };
Then you can update the sorting in this way:
updating = true $("#jqxgrid").jqxGrid('sortby', 'col1', 'asc'); $("#jqxgrid").jqxGrid('sortby', 'col2', 'asc'); updating = false $("#jqxgrid").jqxGrid('sortby', 'col3', 'asc');
Best regards,
Ivan PeevskijQWidgets Team
https://www.jqwidgets.com/Hi Ivan
This is Perfect!
So I have just one more query than expected.
It works and is an excellent compromise, thank you very much!Marco
-
AuthorPosts
You must be logged in to reply to this topic.