-
-
Couldn't load subscription status.
- Fork 154
Description
What are you building with SQLPage ?
Still building the same reporting tool with big numbers in a table 😄
What is your problem ? A description of the problem, not the solution you are proposing.
Since my tables contain a lot of data, it would be nice if it was possible to create a footer at the end of the table with some computed values (e.g. totals or averages)
Describe the solution you'd like
I have already hacked a solution by (ab)using the fact that in HTML you can have a <tfoot> before a <tbody>, and yet everything will be rendered correctly in the end. The solution currently works like this:
- inside the
{{#each_row}}block in handlebars it is easy to know if this is the first row, but it is not possible to know if this is the last one - therefore, I have added a top-level parameter called
first_row_is_footer, so that inside the handlebars template the first row of data is used to build a<tfoot>tag. There are a fewifshere and there to make sure the rendering is still correct when no footer is present. - This might seem strange at first, but it actually works out for most situations. I have a temporary table, and before the
selectthat shows all table contents, I just do aselectwith somesum()s from the same temporary table, so that the code duplication in my SQL files is very little. - As a bonus, it is easy to also add a
freeze_footerstop level parameter to have the footer sticky as well! - As a malus, one has to decide if the footer should have the same "number formatting" using the
toLocaleStringfunction as the table body. For me it is a solid yes, but perhaps in some situations one might not want it, and as far as my changes goes this cannot be choosen user-side
Additional context
I have to clean up some code, and perhaps write an example, but if you are interested I might be able to open a pull request by tomorrow!