adammessinger/Flexitable

Feature request: save column visibility state

Opened this issue · 3 comments

It would be great it there was an option to save the state of the columns (I assume either via localstorage or cookies, or maybe store.js).

Thanks for the feature request, @appel. I've added it to my to-do list.

Thanks @adammessinger, looking forward to it!

I've made some notes about implementation of this feature request that I'm also putting here for feedback and future reference...

  • Keep it compact and simple: array of columns such that keys match column_maps_list, with values of 0 for hidden or 1 for shown.
  • Load saved visibility state array after init (or create it w/ all visible if it doesn't exist).
  • Update visibility array value for a column when user checks/unchecks a column box, but save to localStorage after showing/hiding the column to avoid a slowdown in visual response to user input.
  • Some localStorage issues to keep in mind.
  • Need to give some thought to storage keys. Simply using the table ID could cause data over-writes and unexpected behavior if the plugin user has multiple tables with the same ID. Something like this would work as long as there are no tables with matching IDs at the same URL: 'flexitable_[' + window.location.href + ']_' + view_model.id
  • Be mindful of storage quotas. As a product or site using Flexitable evolves, tables and whole pages may disappear or table IDs may change. Orphaned keys may bloat storage, and there's a slim chance of exceeding quota. Handle the resulting error (and the lack thereof in IE) gracefully, perhaps by (silently?) clearing all Flexitable storage for that domain and then retrying the save.
    • Some quick calculations assuming tables with 24 columns and pages with longish URLs indicate that Flexitable could store up to about 25,000 tables worth of column visibility info per origin for browsers with a 10 MB quota -- half that for some browsers with a 5 MB quota.
    • According to MDN, Safari gives localStorage a quota of 0 in private browsing mode, rendering it unusable. Look into exactly how this manifests in terms of quota errors. Fortunately, other browsers are said to simply treat localStorage like sessionStorage in private mode.