olifolkerd / tabulator

Interactive Tables and Data Grids for JavaScript
http://tabulator.info
MIT License
6.78k stars 821 forks source link

Using column.updateDefinition invalidate sort on remote #4192

Closed ferulisses closed 1 year ago

ferulisses commented 1 year ago

Describe the bug It's a very specific bug, when using remote data, if I use updateDefinition on a column, the next request will lose the sort params on the same column, it occurs only with remote data, only if trying to filter the same column that is sorted

Tabulator Info

Working Example https://jsfiddle.net/8Lqjwu49/5/

To Reproduce

Expected behavior Expect the same result as local filtering: https://tabulator.info/examples/5.4?#popup

Desktop (please complete the following information):

olifolkerd commented 1 year ago

Hey @ferulisses,

this happens because when you update a column, what actually happens behind the scene is that the old column is destroyed and a new column is created with the new configuration.

This will result in any sort/filter on the column being cancelled. The solution to this is to call the 'getSorters' function before you trigger the update of the columns and store the returned array in variable, then after you have updated the columns, call the setSort function passing in the stored values from your variable.

I hope that helps,

Cheers

Oli :)

I

ferulisses commented 1 year ago

Hi,

I tried to use getSorter() before column.updateDefinition and using it after, but the sorter was not restored: https://jsfiddle.net/eyo86pxq/

This should be the default behaviour when using column.updateDefinition.

What else I'm loosing when using column.updateDefinition?

After loosing the sort config, Tabulator send "field: false" to remote server, this is a bug.

The bug doesn't appears to occur when using local sorter and filtering.

ferulisses commented 1 year ago

Hi,

I figure how to create a workaround, the getSorters() return the columns elements that don't exists anymore after running column.updateDefinition.

So, I needed to create a new array without the column elements: https://jsfiddle.net/sxe0fpba/

This works for me, but I still insist that it's a bug, Tabulator should keep the sort by itself when running column.updateDefinition and should not send "field: false" to the server.

md-redwan-hossain commented 4 months ago

Hey @ferulisses,

this happens because when you update a column, what actually happens behind the scene is that the old column is destroyed and a new column is created with the new configuration.

This will result in any sort/filter on the column being cancelled. The solution to this is to call the 'getSorters' function before you trigger the update of the columns and store the returned array in variable, then after you have updated the columns, call the setSort function passing in the stored values from your variable.

I hope that helps,

Cheers

Oli :)

This will cause a new ajax request. The column was already sorted, calling setSort will do a ajax request with the exact same sort parameter as the immediate previous ajax request. Is there any way to stop this unnecessary ajax request? @olifolkerd