Hi guys, I have some troubles using sorting and updating data by calling loadData method.
Look at this example and try to sort column descending within 5 seconds http://jsfiddle.net/andrewQwer/s6t768pq/420/ (after 5 seconds I reload grid using loadData) Sorting indicators stays the same but data is not sorted according to this indicator.
Hi @andrewQwer
I guess I am missing something. Can you share more details on the bug?
When I sort data ascending I haveA, B, C when descending C, B, A and A, B, C without sorting and it is a proper dataset.
Hi @AMBudnik,
Try to sort descending in first 5 seconds. I use setTimeout to load initial data after 5 seconds (A, B, C). So sorting indicator shows that data are sorted descending but they are sorted ascending.
See video for more details: http://screencast.com/t/Z462Ucu1R58
Does it help?
OK, know I know what you mean. Thanks for the video.
It is a bug. I will mark it properly.
Thanks again for sharing @andrewQwer
Thank you!
I have the same issue. Is there an estimated date for a fix?
Hi @sagersx
unfortunately there's no planned fix date yet
@andrewQwer Any good workaround for this?
I found a solution that seems to work:
const { sortColumn, sortOrder } = this.hot
this.hot.loadData(newData)
this.hot.updateSettings({
columnSorting: {
column: sortColumn,
sortOrder
}
})
@TheLudd No, I just forbid sorting :laughing:
beforeChange: function (changes, source) {
//console.log("beforeChange = " + changes);
//console.log("source = " + source);
var hot = this.timeHotHOT;
// handle loadata
if (source === "loadData") {
var plugin = hot.getPlugin('columnSorting');
plugin.saveSortingState();
return;
}
afterChange: function (changes, source) {
//console.log("changes = " + changes);
//console.log("source = " + source);
var hot = this.timeHotHOT;
// handle loadata
if (source === "loadData") {
var plugin = hot.getPlugin('columnSorting');
plugin.loadSortingState();
plugin.sort();
return;
}
This worked for me. Use the beforeChange and afterChange hooks to save/load the sorting state.
On Oct 3, 2017, at 6:17 AM, Ludwig Magnusson notifications@github.com wrote:
@andrewQwer https://github.com/andrewqwer Any good workaround for this?
—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub https://github.com/handsontable/handsontable/issues/3954#issuecomment-333811996, or mute the thread https://github.com/notifications/unsubscribe-auth/ABcAJK26KT7l7XceMHh54KX4WqqxvBt2ks5sohfSgaJpZM4LQzvo.
inform Client from forum
The issue seems to be related to https://github.com/handsontable/handsontable/issues/3582 and https://github.com/handsontable/handsontable/issues/5035
I think that the indicator needs to follow more operations that are performed. Now it's basically changing only if we click a header to sort a column. Maybe it'll become epic?
Hi @andrewQwer
We have recently refactored the columnSorting plugin, along with some fixes and new features. From 6.0.0+ the issue that you're facing can be fixed within this code http://jsfiddle.net/handsoncode/wy1dhpz6/
Hi @AMBudnik ,
The bug is not fixed. Look at the modified example please.
http://jsfiddle.net/wy1dhpz6/1/
If you sort column during the first 2 seconds then new data set will not be sorted accordingly. This behavior was initially reported and it still reproducing.
The problem is that loadData method doesn't respect current sorting state.
I thought that the issue is the indicator being visible after loading data. But, to confirm here, you would like the data to be sorted when loaded with (loadData)?
Correct. If it is designed that loadData call should reset sorting then why does sorting indicator remain the same? Either remove sorting indicator during loadData call, or keep data set sorted according to current sorting options. But I think that loadData should keep current column settings as is.
why does sorting indicator remain the same?
That was actually an issue of the indicator.
When it comes to the order of the data after the loadData call I just raised the subject on the devs meetings and it gets a little bit more complicated.
The loadData itself can be called by the developer but is also called on the initialization. The team did not decide if the change of the order should or shouldn't happen so we decided to mark this case as a feature - to add an option to allow the developer to choose if he wants or doesn't want to change the order.
@AMBudnik Are there any good workarounds for this in the meantime? Neither @TheLudd nor @sagersx's workarounds are working for me on 6.1.1
At the moment, I'm using this, but it feels as hacky as anything else:
settings.afterChange = function (changes, source) {
if (source === 'loadData') {
// restore sorting after data is refreshed
const ColumnSorting = this.getPlugin('ColumnSorting');
ColumnSorting.sort(ColumnSorting.getSortConfig());
}
};
Your workaround looks pretty solid to me @mismith
You can also use the afterLoadData hook
Using that hook does make it a little cleaner, thanks:
augmentedSettings.afterLoadData = function afterLoadData() {
// restore sorting after data is refreshed
const ColumnSorting = this.getPlugin('ColumnSorting');
ColumnSorting.sort(ColumnSorting.getSortConfig());
};
I guess relevant to the discussion above: this seems like this should be the default behaviour in my opinion. For instance, in what case would someone want the sorting of their rows to reset on data change without having the sort indicator reset too? I can't think of one, and it breaks my/user expectations pretty hard, IMO; enough to make me think this is a bug rather than a feature. 2¢
Thank you for sharing @andrewQwer
This feature request is closed.
It will be automatically reopened after we attach it to a milestone.
Most helpful comment
Using that hook does make it a little cleaner, thanks:
I guess relevant to the discussion above: this seems like this should be the default behaviour in my opinion. For instance, in what case would someone want the sorting of their rows to reset on data change without having the sort indicator reset too? I can't think of one, and it breaks my/user expectations pretty hard, IMO; enough to make me think this is a bug rather than a feature. 2¢