Shiraz dynamic tables and calculated column value

Hi !

I am using shiraz dynamic tables plugin : Shiraz 2.7.6 — create stylish contents in Tiddlywiki.

And I would like to have a column which is a calculated value from the fields of the items in the table.

I tried to use a custom column template : Shiraz 2.7.6 — create stylish contents in Tiddlywiki, and I managed to get the column with the correct value, but then it is not sortable.
I looked at the code, and I saw it has to be a field to work correctly.

So I tried to put a macro in the field on my tiddler, it show the correct value when I do {{my-tiddler!!my-field}}
But then, it show only 0 inside the dynamic table.

What is the correct way to do it ?

Thanks !!

Tip: If each column is a field then you need a filter that sums that fields value for all the tiddlers in the table; typically using a reduce filter run.

Hi, thank you for your answer !
I have my filter, it is something like : [{!!price}divide{!!weight}divide{!!proteins}multiply[100]fixed[3]]

But the difficulty I have, is to be able to use it with dynamic tables, without breaking sorting.

To expand on this: the dynamic table macro is designed to allow sorting based on the value of a field, but if that field contains a filtered transclusion to be evaluated, the sorting applies to the literal filter, not to its wikified output. I suspect this would be tricky to do without substantially changing the way the macro works… @Mohammad, do you have any insight? Does this sound possible?

2 Likes

Hang on… I think I can get this one…

(See other replies for OP’s complication, but just for the sake of the thread archive, for others who want help with just getting the right value to show up in dynamic tables – since you need to know more than the usual filter to get this working):

You need a column template, tagged $:/tags/Table/BodyTemplate with tbl-column-list field set to whatever you want the table column header to be, and content something like this (I haven’t tested, but built from comparable elements in my own solution):

<$tiddler tiddler=<<currentRecord>> > <$text text={{{ [{!!price}divide{!!weight}divide{!!proteins}multiply[100]fixed[3]] }}}/> </$tiddler>

-Springer

2 Likes

Ah, I think I agree with @etardiff. I’ve tried to sort on a calculated column before, and it doesn’t seem like the dynamic tables can “peek” into the calculation to sort by the result…

Sorry my previous reply was just expressing confidence about getting the values to show up right within a column template.

1 Like

It’s my fault for not being clear that I’ve already tested this.
And I should have indicated how, for those for whom breaking the possibility of sorting by these columns is not important.
So thank you for fixing this oversight.

1 Like

I always imagine how reading a thread might feel for someone whose problem is adjacent-enough to the OP that the title looks hopeful. :slight_smile:

1 Like

That is right! Dynamic table transcludes the field, but if field itself contains transclusion! then nested transclusion does not work and need its own column template to handle this! @Springer has given the solution above!

1 Like

Hey !
I don’t get it, I tried using column template but it broke the sorting mechanism. Can you explain how it should be done ?

What do you mean by “broke the sorting mechanism”? @etardiff and @Mohammad and I have all been agreeing you’re not going to be able to sort on the calculated column, and I thought that was clear.

Do you mean the table doesn’t sort at all now?? Even after doing the steps here?

Hi @dionisos
The sort works like this upstream-filter-stepsort[]. The upstream filter (or inputfilter) shall return a value not transclusion.

It would be helpful to setup a test wiki with minimum non-private data and share here. By the way I believe @Springer has given the answer to OP.

I am sort of lost.
From what I understand etardiff, I, and you, was unsure it was possible or not.
But Mohammad said “then nested transclusion does not work and need its own column template to handle this!”
Which I am unsure to understand correctly. But I tried to make it works with a column template, and the sorting wasn’t working. (and from the code I read, it seems it can’t work like that)

So I am still confused about how to do it, or if it is possible at al.

The upstream filter (or inputfilter) shall return a value not transclusion

But how should I do it if I want it to be the result of some operation, is there a way to do it without a transclusion ?

If I have some tiddlers with two fields, X and Y, and I want a sortable column X+Y ?
Is it possible ?

I think Mohammad’s agreeing that it’s not possible given the way the macro currently functions.

It wouldn’t be quite as elegant as an automatically-calculated value, but depending on how often you expect the fields to change, you could add a button next to the table that sets each field Z to the result of each respective X+Y whenever it’s clicked. That would give you a single numeric value for each Z, which you could then sort like any other field.

Depending on how you’re setting X and Y, you might even be able to incorporate an action widget to update Z whenever X or Y changes. The edit-text widget accepts an inputActions attribute; several others, like the select widget, use actions.

2 Likes

@dionisos
Would you please share a test wiki to see how your tiddlers looks like? and the template you are using?

No it is not possible! Dynamic table will return zero for Z column. See below posts.

A test example

  1. download test-dynamic-tables-fields-contains-ransclusion.json (538 Bytes)
  2. drag and drop test-dynamic-tables-fields-contains-ransclusion.json into Shiraz 2.7.6 — create stylish contents in Tiddlywiki
  3. open Test Dynamic Table with Fields Contains Transclusion and note to column Z

@dionisos I cannot help without a minimum test wiki as we don’t know how your data and template looks like!

Conclusion Notes:

  1. To be clear dynamic table does not work with transclusion of transcluded data (e.g. nested transclusion)
  2. In the above example field Z in Tid01 looks like {{{ [{!!x}add{!!y}] }}} what about if I use {{{ [{Tid01!!x}add{Tid01!!y}] }}} (use explicit transclusion)? It will work, but in Shiraz I do not recommend it! because it is brittle and users may use a mix of implicit and explicit transclusions. Se the below example (uses explicit transclusion) works test-dynamic-tables-fields-explicit-transclusion.json (812 Bytes)
1 Like

Thank you all for your answers, and sorry for the late response !

I cannot help without a minimum test wiki as we don’t know how your data and template looks like!

Here is what I did : Test — Test Dynamic Table with Fields Contains Transclusion

<$let currentTiddler=<<currentRecord>> >
{{{ [{!!x}add{!!y}] }}}
</$let>

Btw, I suppose there is a way to do it without the “let”, but I didn’t find the correct syntax.
(Also, I know I should add the part for the edit/view mode, like explained in the documentation, but I just wanted a simple example)

To be clear dynamic table does not work with transclusion of transcluded data (e.g. nested transclusion)

Ok, So I think I will use @etardiff solution, and use an action widget to update the fields of all my tiddlers with a button !
(but still use a transclusion when I show the calculated value anywhere else, so I don’t need to update the fields except when I want to see the dynamic table)

You won’t be able to edit the values for the z column anyway, so you don’t need the edit mode. :slight_smile:

You should probably change your z-calculations to use
<$text text={{{ [{!!x}add{!!y}] }}} /> so that the added numbers don’t appear as links.

1 Like