-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: hiding a column by which the table is sorted breaks multi column sorting
#546
Comments
Unfortunately, you can't change how columns are being hidden/shown, if you do that will be a major breaking change and will break many user's grids including all my libs. I agree that it shouldn't have been done that way but that's the way it is and we're stuck with the behavior, which is to call The only possible and acceptable way to fix this would be to add a new variable internally ( |
@ghiscoding I believe if we could add a flag to anyways, // slick.grid.js:1409-1414
/*1409*/ trigger(self.onSort, {
/*1410*/ multiColumnSort: true,
/*1411*/ sortCols: $.map(sortColumns, function(col) {
/*1412*/ return {columnId: columns[getColumnIndex(col.columnId)].id, sortCol: columns[getColumnIndex(col.columnId)], sortAsc: col.sortAsc };
/*1413*/ })
/*1414*/}, e); |
That code is not bullet proof and should be rewritten a bit to avoid throwing errors, something like this maybe. var columnIdx = getColumnIndex(col.columnId) || -1;
var column = columnIdx >= 0 ? columns[columnIdx] : null;
return {columnId: column && column.id , sortCol: column, sortAsc: col.sortAsc };
No it doesn't, it assumes that you will pass all columns when you create the column picker, it creates a local copy of the columns at grid creation then uses that copy when it needs to refer to all columns, it also has a 2nd variable So in brief, what I wrote in previous post is still the best way (probably the only way) to go, the library should have a copy of |
My 2c - in setColumns() should we just iterate sortcols and remove any missing column ids? This would mean that the hidden column was removed from the sort, but it would prevent an error occurring. |
I would say Yes disregard columns that don't exist at least until someone takes the time to add something like |
@ghiscoding @6pac I'd rather work on the |
You are most welcome to create a PR to add the |
@ghiscoding I took a more accurate look at how the unfortunately, the functions |
this should be fixed by #765 and released under the new v4.0.0-beta.0, so it should be safe to close this issue |
please use the following example:
.txt
suffix,examples
folder% complete
,start
.start
column.finish
to sortvoila! check your browser's console, and you will see the message! the behavior is visualized in the following GIF.
the reason behind this behavior is that
slick-grid
changes the entire column-set each time a column is set to be hidden; which causes thegetColumnIndex
function to returnnull
, as the hidden column is not on the list of columns; obviously!the solution is more complicated as far as I can tell! because many plugins and existing codes depend on the current implementation of the
getColumns
andgetColumnIndex
functions, it's not easy to add a property - for example, calledvisible
` to the column definition in order to control column visibility. hiding or showing columns shouldn't be a matter or setting a new column-set, but rather a matter of changing their visibility and redrawing the whole table!example-multi-column-sort.html-broken.txt
The text was updated successfully, but these errors were encountered: