jQuery UI Widgets › Forums › Grid › VirtualMode and Sorting, how to pass sort arguments
This topic contains 2 replies, has 2 voices, and was last updated by Martin 6 years, 7 months ago.
-
Author
-
I’ve implemented sorting with virtualmode based on the examples, and it works for the most part. The only problem is I need to pass sort arguments to another function to update another user-view of the dataset, these don’t seem to be available. Previously I used the on.(sort) event since it has the necessary arguments such as sort direction and sort column that I can pass to my function. But this resulted in problems due to changing before bindingcomplete I think. So I went back to the method below and instead used bind.(sort). The problem now is bind.(sort) is called whenever I scroll the grid after sorting a column.
Also, I still seem to be getting the bindingcomplete error if I sort a column, then click the arrows on the scrollbar. If I scroll or drag the scrollbar, no errors.
var url = "/spreadsheet.php?p="+query; // prepare the data var datafields = [ { name: 'id', type: 'string' }, { name: 'TEST', type: 'string' } ] var source = { datatype: "json", datafields:datafields, url: url, cache: false, root: 'Rows', beforeprocessing: function(data) { if (data != null) { source.totalrecords = data[0].TotalRows; } }, sort: function() { // update the grid and send a request to the server. $("#spreadsheet-data").jqxGrid('updatebounddata', 'sort'); }, };
$("#spreadsheet-data").bind("sort", function (event) { var sortInfo = event.args.sortinformation; var sortdirection = sortInfo.sortdirection.ascending ? "ASC" : "DESC"; var sortColumnDataField = sortInfo.sortcolumn; recordRetrieve(1,query_crypt,sortColumnDataField,sortdirection); });
Ok, I’m an idiot. on.(sort) is called everytime the grid is scrolled too. Also, the bindingcompleted error no longer occurs when using on.(sort). I might have fixed it unknowingly.
That said, what is a solution to pass the current sort arguments only once, after every time a column is sorted? The other user view is a single record view that can be sequentially navigated. I need the sort information so that these records are in the same exact order as the grid view.
Hello mykal,
The sort event is fired every time you scroll the grid, as new data is loaded and the sorting is executed again.
So, as a solution to your issue, I would suggest you to keep the first sorting information (from when a column is sorted), and then to pass the arguments
only if there is a difference in the information, which would mean that a column is sorted again. When scrolling, the sort info remains the same.
I hope that this suggestion would help you!Best Regards,
MartinjQWidgets Team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.