What kind of variable should I use?

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?

  1. 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).

  2. 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.

  3. 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!

I have asked the same question on Stack Overflow. A helpful pointer is that #1 will re-render every table on a page when one is updated–no good!

Just to make sure – datatables aren’t an option? There are already some community wrappers for this library.

Tabular and Reactive tables both get bogged down when dealing with large databases. The ones I’ve made are faster and more versatile (for our needs).

How about a client-side collection with a doc for each table?

That could work too; might do collections in the future to store settings between sessions on a per-user per-table basis. I went with separate Session variables for each table (which isn’t effectively much different than a client-side collection). Thanks!

No worries, hope that works out!