How can I preserve user selected sort order while giving precedence to initial sorting
How can I preserve user selected sort order while giving precedence to initial sorting
rmaitipe
Posts: 9Questions: 3Answers: 0
I tried the stateSave option and it worked great - but ran into problems because it ends up overriding the initial sorting when the page is loaded next time.
My table initialization code looks like this.
$('#ResultsTbl').dataTable( {
"bPaginate": false,
"bSortable": true,
"bDestroy": true,
"bFilter": false,
"stateSave": true,
"bInfo": false,
"aaSorting": [[8,'asc']],
"oLanguage": {"sZeroRecords": "", "sEmptyTable": ""}
});
This discussion has been closed.
Answers
I'm afraid I don't understand how you can both preserver user selected order and allow the initial sorting condition to take place. It seems to me you can have one or the other, not both at the same time?
Allan
Hi Allan, to clarify - In the page users can edit and save records and it will preserve the sort order as intended. But if they refresh the page or go to different page and come back to it I'd like to have it use the initial sorting.
The documentation says if the url changes the state information is lost, but in my case it still seem to persist. I tried using table.state.clear() - but it caused the page to get stuck on ajax spinner when loading.
I'm not clear why you would use state saving at all in that case? If you want a visit to a different page and then back, or reloading the page to restore the initial sort, don't save the state.
Sorry - I'm confused!
Allan
Hi Allan, Sorry if I'm not making myself clear. The way users utilize the screen is when them come to it first, initial sort kicks in and sorts by a date column and displays items needing immediate attention first. Then they might sort by name to see what other records are in for that name, then edit some of them and submit the changes. This is where users asked to keep the selected sort from changing and I thought the state save might help.
However with the state save on, if they change the pages and come back it shows the last user selected sort instead of sorting by urgency. Again if this is something incompatible with each other and they just have to click the column again, that's fine.
Do you mean that they don't want the table to re-sort based on the new data? Or are they editing the data on a different page and then you come back to it?
Allan
Hi Allan, The first one - once the data is saved by the user, data is removed from that list - so there won't be new data until the web page gets reloaded. Currently the main use seem to be sorting by type so I might be able to use filtering as a compromise if there isn't a way to reconcile the initial sorting and the state Save
I'm just too thick - I'm totally not getting this I'm afraid. If you are removing data from the list, then even if you resort the table with the existing sorting conditions, the order will be the same, just minus the old row.
Can you give me a link to the page with step by step instructions on how to trigger what you are currently seeing and then what you want to see please?
Thanks,
Allan