I have a series of templates that I designed for making interactive tables: sortable column headers, pagination, reactive counter of table’s elements, etc. Up until now I have been storing several pieces of information (current page, items per page, and sort order) as session variables so that it was easy to access them from every template regardless of their relationship (parent, sibling…) to eachother.
This has worked alright until now, but now I want multiple tables on the same page. Since I have statically-named session variables, information gets overwritten by other tables on the page.
I am working on a bunch of solutions and welcome other suggestions. What do you guys think?
-
Name every table and store all the information for every table on the site in a giant session variable, which would be an object keyed by tables’ names. The downside here is that every table would need a unique name and I’d have to keep track of that. The upside is that implementing the table in new parts of the system could be easier than ever. Also, table sort/filter/page information would be stored even when leaving pages (but could be overridden if that were desired).
-
On the template that contains all the table parts, define reactive variables, then explicitly pass those down to lower levels with helpers. This would help with our goal of cleansing the system of session variables floating around (not that all session variables are bad), but would be a trickier refactor and harder to implement new tables with. Information would not be remembered when navigating between pages.
-
Each table template could reference the parent’s reactive variables (messy, but possible) and look for specifically named ones (such as “table_current_page”). This would make setup of new tables easier than #2, but would only allow one table per template (but multiple per page would still be possible).
None of these are quite ideal, but I am leaning towards #1 or something like it. Suggestions? Thanks!