[dokuwiki] Is there really no simple table column arithmetic in Dokuwiki?

  • From: Tero Kivinen <kivinen@xxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Mon, 16 Sep 2019 05:26:23 +0300

Chris Green writes:

Am I missing something or is it really not possible to add up a column
of numbers in a table in Dokuwiki?

The only plugin I can see that does anything remotely like this is the
tablemath plugin but it's very old and also rather clumsy in that one
has to actually specify the first and last row to be summed.

We have been using modified version of tablecalc to do that.

Surely there's a case for a plugin that provides syntax like:-

^ Hdr1 ^ Hdr2 ^ Hdr3 ^
|  2   |   4  |  1.9 |
| 17   |  32  |  2.4 |
| 12   |   3  | 12.4 |
|~~sum~~|~~sum~~|~~sum~~|

If there really isn't anything like this I might actually start
thinking about how to do it myself (maybe start from tablemath but
simplify the usage).

In our case we have sumc function that takes column number as argument
and sums all numbers in given column from the first row to the row
above of sumc cell. If the column number is -1 then it counts current
column:

| ~~=sumc(-1)~~ || ~~=sumc(1)-sumc(2)~~ |

Modifying the tablecal was quite easy as all calculations happens in
javascript, so you just need to write suitable javascript functions
and make sure syntax.php allows those.

It also seems that tablecalc has already been update to support
r0c0:r22c0 syntax so you can write ~~=sum(r0c0:r22c0)~~ to calculate
sum of rows 0-22 of column 0.

They do still recommend using range function instead so you do not
refer to nonexisting cells, but that gets bit hard to parse when you
have long expressions ~~=sum(range(col(),0,col(),row()-1))~~.
-- 
kivinen@xxxxxx
-- 
DokuWiki mailing list - more info at
http://www.dokuwiki.org/mailinglist

Other related posts: