Stuck when trying to improve my "editable table" procedure

For a long time, I have been looking for a way to quickly create editable tables for my tiddlers, but couldn’t find what I was looking for.
So instead, I decided to create my own solution.

It is inelegant and still unfinished, but it works. One of the improvement I would like to do is allow multiple tables per tiddler.
But maybe I should describe what work before moving on to what doesn’t work ?
This will give you the context behind my problem.

In truth, my <<TableGenerator>> don’t create a table, but a grid with “number of column” childs of 1fr width per row. I also pre-created children for this grid. They are numbered from 1 to 50 and revealed if column*row is superior or equal to their individual numbers.

To summarize, when you ask for a table of 3 columns and 4 rows, you receive an html grid of 3 columns containing 3*4=12 visible divs that you can edit, and 38 hidden empty divs.

As the code is quite long, I’ve uploaded the tiddler, in case someone want to have a look: Table Generator Procedure.tid (25.4 KB)

So yeah… It work…

But because it read the number of columns and rows from preset fields, I can only have 1 editable table per tiddler. I would like to be able to have multiple tables per tiddler if needed.

A solution would be to give each table a name :
<<TableGenerator name:”Table1”>>
And then add the table name as a prefix or sufic to all generated fields.
This is were I am stuck.

Having a text area refer to the field “nb_column_Table1”, this name being generated by the procedure, work as intended. The field “nb_column_Table1” is created and host the user-input.
But I can’t find how to load these fields values in a filter run or in a CSS.
Here is a short code exemplifying my problem :

<$let
TN={{!!TableName}}

nb_rowS={{{ [[{{!!nb_row_]] [<TN>] [[}}]] +[join[]] }}}
nb_columnS={{{ [[{{!!nb_column_]] [<TN>] [[}}]] +[join[]] }}}

nb_column={{{ [[nb_column_]] [<TN>] +[join[]] }}}
nb_row={{{ [[nb_row_]] [<TN>] +[join[]] }}}

nb_rowV={{{ [[{!!]] [<nb_row>] [[}]] +[join[]] }}}
nb_columnV={{{ [[{!!nb_column_]] [<TN>] [[}]] +[join[]] }}}

total={{{ [[<nb_columnV>]multiply[<nb_rowV>]] }}}
>

table name :<$edit-text field="TableName"/><br>
column :<$edit-text field=<<nb_column>>/><br>
row :<$edit-text field=<<nb_row>>/>

columns :<<nb_columnS>><br>
rows :<<nb_rowS>><br>
total :<<total>><br>
</$let>

My question is :
I already have the name of the field I want to load (nb_column_{{!!TableName}}) stored in a variable. Now, is it possible to load the corresponding field value into my “total” variable in order to multiply it?

Or is it a dead end and should I opt for an other approach ?

1 Like

In a filter, you can get the value of a field using the get operator, eg: [[myTiddler]get[myField]].
If the field name is in a variable, you can use this syntax: [[myTiddler]get<myVariable>].

Thus, assuming the field name is available in variable fieldname for current tiddler, here’s the code:

<$let
  total={{{ [<currentTiddler>get<fieldname>] }}}
>
...
</$let>

Fred

1 Like

Thank you, it worked like a charm.