-
-
Notifications
You must be signed in to change notification settings - Fork 39
feat!: switch to column hidden property and always keep all columns
#2281
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
base: next
Are you sure you want to change the base?
Conversation
…stFrozenColumnIndexWhenNeeded()
|
|
angular-slickgrid
aurelia-slickgrid
slickgrid-react
slickgrid-vue
@slickgrid-universal/binding
@slickgrid-universal/common
@slickgrid-universal/composite-editor-component
@slickgrid-universal/custom-footer-component
@slickgrid-universal/custom-tooltip-plugin
@slickgrid-universal/empty-warning-component
@slickgrid-universal/event-pub-sub
@slickgrid-universal/excel-export
@slickgrid-universal/graphql
@slickgrid-universal/odata
@slickgrid-universal/pagination-component
@slickgrid-universal/row-detail-view-plugin
@slickgrid-universal/rxjs-observable
@slickgrid-universal/text-export
@slickgrid-universal/utils
@slickgrid-universal/vanilla-bundle
@slickgrid-universal/vanilla-force-bundle
commit: |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #2281 +/- ##
=======================================
Coverage 100.0% 100.0%
=======================================
Files 198 198
Lines 18215 18256 +41
Branches 5010 5021 +11
=======================================
+ Hits 18215 18256 +41
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This is a breaking change and will be scheduled for the next major version, Q1 of 2026
Description
For years, I had to use a Shared Service to keep references for both
shared.allColumnsandshared.visibleColumns, for translating locales also used by Column Picker and Grid Menu to keep track of which columns to hide/show, we then callgrid.setColumns()to update the columns in the grid... but this as side effects since SlickGrid never kept the entire column definitions list, on the other end if we just start using ahiddenproperty on the column(s) to hide some of them, then we would be able to keep the full reference at all time to these columns. We can then just usegrid.getVisibleColumns()which behind the scene is simply doing acolumns.filter(c => !c.hidden).With this change, I still keep a reference to
shared.allColumnsbecause that can be useful when we need to reset to the original column positions. For example if we reordered the columns to different positions and we want to reset to the original columns like Example 11 with Saved Views (Grid State)Note that we already had the
hiddencolumn property that Ben (6pac) added in SlickGrid, but it was a bit incomplete, not fully tested and not used by the Column Picker/Grid Menu... this PR now takes full advantage of this approach. With thehiddenapproach, it's better to "go all-in" because there side effects related to this approach (see below)Advantages
We no longer have to keep a reference of the visible columns because we can now simply use
grid.getVisibleColumns(), which again is simply just a filter that returns a list of columns that doesn't have thehiddenproperty. Another advantage is that we can translate the locales a lot easier with the new code because we keep all the columns (with the previous code, I had to keep reference to all columns, but also keep the order of the columns and visible columns, translate them and then reapply the columns withgrid.setColumns()). The other advantage is that the internal code is much more simple because we just need to change thehiddenflag instead of using the Shared Service.grid.setColumns(visibleCols)grid.updateColumnById('gender', { hidden: true });andgrid.updateColumns();sharedService.allColumnsgrid.getColumns()sharedService.visibleColumnsorgrid.getColumns()grid.getVisibleColumns()Disadvantages or Side effects
There are some side effects related to this new approach of using
hiddencolumn property, more specifically withcolspanandrowspan. With the previous code, if we had spanning then the hiding a column would simply move over the same spanning to the next column. However with the new code, hiding the column will keep its spanning(s) but will be hidden as well, the other columns spanning(s) will remain on the same column indexes. I think in the end, the new code is actually much more predictable and so I'm inclined to say that the new behavior is better and more predictable (see below).There's also another side effect which I think is also ok which is that since we would keep all columns but just toggle their
hiddenproperties, then afrozenColumnwould also follow and stays with the same column forever. Prior to this PR, with the old code, I had to keep a ref of the column ID and recalculate thefrozenColumnindex. So with the new code, I can get rid of the code that was recalculating the frozen column index, it's less code and also more predictableNotes
The
hiddencolumn property means that the cell won't be rendered in the DOM (it's simply skipped), but its column index still exists. For example if we have 3 columns and the middle one is hidden, then the first cell class isslick-cell l0 r0and then the last cell is also shown withslick-cell l2 r2(notice thatl1 r1isn't displayed but its indexed is kept). This introduced some challenges with colspan/rowspan, more specifically the keyboard arrow navigation because of these ghost index when the column is hidden but their index are still preserved. So anyway, that's why it took me over a month to figure out how to fix them and find all these new side effect bugs that we didn't see before because we previously wipe the array withsetColumns()and we didn't previously have blank holes in the middle, so it's a bit of a challenge now but still is the correct approach I think.Another note is that with Grid Presets if we were to provide a list of columns that had less columns than the original list, it meant that the ones missing were considered hidden columns. However with the new approach, we have columns with potentially
hiddenprops, but I think it can be useful to support both approaches. So with the Grid Presets, I now support both approaches, the user can still use the old approach (less columns equals to hidden columns) and the new approach (all columns but some withhiddenflag). Supporting both is great because that means that if the user had any old Grid States saved (to use as Grid Presets when loading a grid), then it would still work.Conclusion
I think that the
hiddenis really what SlickGrid should have used from the start, I find it to be the correct way of handling visibility while always keeping the columns reference (for example it's a lot easier to deal with translations). Perhaps it wasn't obvious that this was useful before the Column Picker/Grid Menu were later added to the project, but now that we have them, usinghiddenmakes more sense. The end goal now would be to push the user to stop usingsetColumns()but now start using the new functionupdateColumnById('id', { hidden: true })and thenupdateColumns()(notsetColumns()since that would erase the reference to the full columns ref)Left Side: previous code ➡ Right Side: new code

cc @zewa666 @6pac