sorting using refrenced values

100 views
Skip to first unread message

paulgilbert2000

unread,
May 17, 2021, 9:45:20 PM5/17/21
to TiddlyWiki

Hi ,

is it possible to sort transcluded /referenced values?

so i have tiddler 1 which has 3 fields ,field x , field y and field z

field x = 1
field y = 2
field z=  {{!!field x}}{{!! field y}}  --> which translates to "12"

Now i have the same exact thing happening for 4 or 5 other tiddlers with different values for field x and field y , and field z referencing them

now i am doing a list filter , that lists said tiddlers , and putting a sort at the end ..

so something like <$list filter=  criteria ..... and then towards the end     [sort[ field z ]]">


 The sort is working, i also used nsort with no luck , so is there something i am doing wrong, or referenced values cannot be used as a criteria for a sort ?

Thanks in advance





Michael Wiktowy

unread,
May 18, 2021, 8:03:46 AM5/18/21
to TiddlyWiki
Not exactly what you want but if you can express your combination of field x and field y as a filter expression, you should be able to use sortsub.
/Mike

Michael Wiktowy

unread,
May 18, 2021, 10:41:19 AM5/18/21
to TiddlyWiki
For instance, in your specific example you could use a filter like [{!!x}multiply[10]add{!!y}] in the sortsub for your list of tiddlers containing x and y ... you don't need a z field for this particular use.

So if you had a bunch of tiddlers tagged with "sortbyfield" you can do:

\define ssfilter() [{!!x}multiply[10]add{!!y}]

<$list filter="[tag[sortbyfield]sortsub:integer<ssfilter>]"/>

This works for your particular example that you provided because you can do math in the filter. Not sure how easy it would be in the general sense.

/Mike

paulgilbert2000

unread,
May 18, 2021, 6:58:08 PM5/18/21
to TiddlyWiki
Thanks Mike,

so basically i am trying to do is simulate a ticketing tool.. , and assign prioritys to tiddlers i am using as tasks ,  2 criteria(severity , impact) or more  that add up to a given priority/ranking ,

so tiddler A is called " archive data"

field x is  "severity" and  has value 1111111
filed Y is  "impact"  and has value 111111111
Field z is "priority" and  has value {{!!severity}}{{!!impact}} --> translating to 1111111111111111

tiddler b is called "restart server"

field x is  "severity" and  has value 11
filed Y is  "impact"  and has value 11111111111
Field z is "priority" and  has value {{!!severity}}{{!!impact}} --> translating to  1111111111111



they also have another field "status" which can be either " In House " or " With Vendor" , so thats another 4th field that will hold any of these 2 values .

then...

<$list filter=
"[status[In House]][status[With Vendor]]+[sort[priority]]">



Now ,The reason i am using ones in the field values (ie 11111) is because , i understand you cant do math in fields .. which is another problem ..

but then my thinking was ,i run a filter on all tiddlers which has "In house " or "With Vendor " in the status field values 
[status [In House]][status[With Vendor]]

then sort them using the priority field , and that should sort the tiddlers with the higher ranking at top, and thats when i realized the sorting doesn work , hence this post.

i have few questions

if i understood correctly you are saying this can be done using tags instead ?
so can it be done using field instead (so instead of  [tag[sortbyfield], could it be [status [In House]?
also how can i view the outcome of the mathematical operations?

and finally , now that you know what i am after , is there a better way of doing all this ?

Soren Bjornstad

unread,
May 18, 2021, 7:11:02 PM5/18/21
to TiddlyWiki
So the reason sorting by the "priority" field doesn't work is because the field literally contains the text "{{!!severity}}{{!!impact}}". Those transclusions only get processed and turned into a series of 1's when the field is wikified, which normally happens right before it's displayed within the tiddler. If you access the priority field through a filter or pass it as the value of an HTML/widget attribute, it will still just contain the text. (More on wikification.)

That's probably not a great way to do it anyway, since you have to manually put that text in every tiddler.

The point of Mike's snippet wasn't the tag part (I don't think tags have anything to do with your use case) – that was just a placeholder for whatever filter steps you needed to select the relevant tiddlers. The important part was the sortsub operator, which runs a filter expression against each element to determine how to sort it. In your case, I think you would want something to the effect of:

\define sortformula() [{!!severity}add{!!impact}]

<$list filter="[status[In House]] [status[With Vendor]] +[!sortsub:integer<sortformula>]">
<$link/> (priority <$text text={{{ [{!!severity}add{!!impact}] }}}/>)<br>
</$list>

(For this to work you need to switch to the actual numbers, rather than a string of 1's. Also note that the filter you gave above for tiddlers with a particular value in the status field is incorrect because it contains a space after the word status – a space isn't allowed there.)

The {{{}}} allow you to transclude the result of a filter expression...so that's how you "view the outcome of the mathematical operations".

paulgilbert2000

unread,
May 18, 2021, 7:39:47 PM5/18/21
to TiddlyWiki
Thanks Soren/Mike,

I got it to work exactly as you have explained :)

BTW congrats on Grok TiddlyWiki, i am already reading through it ,and find it extremely well written and easy to understand for beginners like mys self

Thanks again Soren and mike :)

paulgilbert2000

unread,
Jun 1, 2021, 8:30:35 PM6/1/21
to TiddlyWiki
ok one more thing,

it seems the mathematical operations only occur when the values are being entered , if i save the wiki and open it again , the operation does not happen on the stored values i entered in a previous session

so if i set the severity(via radio buttons)  to "1" , and the impact to  "2" , i can see the priority as "3"

if i close the wiki and comeback , i find the priority set back to 0 , i actually also realized that the radio button resets, and does not save what i have checked in a previous session

is this normal, or am i doing something wrong ?
Reply all
Reply to author
Forward
0 new messages