0

Is it possible to add a total row in inputs.Table from Observablehq? The idea is to have a column aggregate such as sum or mean. I searched through the inputs.Table documentation, but it does not seem to mention this option. In addition, I could not find any notebook showing this option either. If this option is not implemented in inputs.Table, do you believe it is feasable to improve the source code to have this functionality for someone relatively new to JavaScript? I had a look, and was kinda of lost in the source code, but maybe with a little guidance from someone more experienced, I could be able to modify it by myself. Alternatively, how can one add the totals using an external library?

Jakub.Novotny
  • 2,912
  • 2
  • 6
  • 21

2 Answers2

2

This isn't something that inputs.Table supports directly. I'm not sure if it is something that the maintainers of that library would want to include, but it is an issue that has come up before: https://github.com/observablehq/inputs/issues/148. I think you could post there to try and get some guidance about how to move forward.

Another thing you could do is to modify the data you are passing to the table to add those rows. I made an example of that: https://observablehq.com/d/ed915b04358db27c. There isn't a way to style those rows separately though.

Mike Cooper
  • 2,928
  • 2
  • 26
  • 29
  • This is a nice approach. My idea was to have the original table, and then add a second table with totals below, but without headers and formatted in bold, but I could not make it work. – Jakub.Novotny Aug 18 '22 at 08:52
0

Using an external library, one can easily generate a table with totals. An example of such a library is Tabulator. Here is an example notebook.

enter image description here

Jakub.Novotny
  • 2,912
  • 2
  • 6
  • 21