sum cells in a table only if row is selected

74 views
Skip to first unread message

Willy Tanner

unread,
May 31, 2021, 4:43:34 AM5/31/21
to TiddlyWiki
Hi
perhaps someone can help me with this. I have a table in Tiddlywiki with the weight and dimensions of pieces of equipment that I need to take with me on a trip with tight baggage limits. As some of the items in that lists are alternatives, I do not need a sum of the entire column but rather the total weight of pieces that depend on item X but make no sense if item Y is taken instead. 

Is it possible to play through different scenarios by simply selecting and deselecting rows in a table that correspond to different solutions and have the sum update to reflect only the selected cells? I can manage the selection process manually, so defining sets of interdependent items is not needed here. 

Thank you
Christoph

Mat

unread,
May 31, 2021, 3:19:25 PM5/31/21
to TiddlyWiki
How is your table implemented? Calculating the sum of a column is not a standard feature in TW, so maybe you're using some plugin?

But (probably) regardless, it should be doable, yes. One idea would be a column at extreme left or right with checkboxes. Instead of selecting, you check the relevant rows, and there is a sum calculated from this. It could work so that the selected titles are added to some list, and the sum is calculated by extracing and summing up the weight from all the listed items.

<:-)

Willy Tanner

unread,
May 31, 2021, 4:09:31 PM5/31/21
to TiddlyWiki
For the time being, it is just the table, no sum total of weight or anything yet. I have not expressed myself well what I meant with "selected" but your guess is exactly what I wanted to say, i.e. selecting which gear to take by putting a checkmark next to it. 

As I said, for the moment there is nothing but the idea in my head. By the looks of it the table calculations might be helpful but I am all ears if I should try something else for some reason. 
By default, it does not cover my main incentive, namely summing up only the values in rows with an active checkmark. 

I'd be grateful for any suggestions 

Mat

unread,
Jun 1, 2021, 2:50:47 AM6/1/21
to TiddlyWiki
OK, since you didn't decide on any particular solution, here's an untested rough outline.

<table>
<$list filter="""[criteria for whatever tiddlers should be listed]""">
<tr>
<td><$link/></td>
<td>{{!!myvalue}}</td>
<td>
   <$button>
      <$action-listops $tiddler=tempsum  $field="selected" $subfilter="""+[toggle<currentTiddler>]""" />
      <$list filter="""[ [tempsum]get[selected]search<currentTiddler>]""" emptyMessage=add > --- </$list>
   </$button>
</td>
</tr>
</$list>
<tr>
<td style="text-align:right">SUM:</td>
<td>{{{ [[tempsum]get[selected]enlist-input[]get[myvalue]sum[]] }}} </td>
<td></td>
</tr>
</table>

It is probably buggy. For example, if it shows anything at all, test if it gets the correct sum if several of the items have the same myvalue. 

By the way, that button code will be greatly simplified/removed if we had this to show a checkbox instead.

<:-)

Reply all
Reply to author
Forward
0 new messages