[TW5] Multiple sorts of filtered tiddler list

1,568 views
Skip to first unread message

Tim Brown

unread,
Nov 25, 2015, 6:39:47 AM11/25/15
to tiddl...@googlegroups.com
Hi,

I would like to be able to sort a filtered list using multiple fields - surname and givenname specifically.
I tried the following:

<<list-links filter:"[tag[client]sort[2_surname]sort[1_givenname]]">>

Is sorting based on custom fields supported and are chained sorts supported?

Thanks in advance

Tim

Jed Carty

unread,
Nov 25, 2015, 7:28:58 AM11/25/15
to TiddlyWiki
Sorting on custom fields is supported and what you have for that should work. The chained sorts don't work. To get that you have to use nested list widgets like this:

<$list filter='[tag[client]each[2_surname]sort[2_surname]]' variable=Surname>
<$list filter='[tag[client]2_surname<Surname>sort[1_givenname]]'>

</$list>
</$list>

The first filter gets all tiddlers with the tag client then finds every unique entry in the 2_surname field and sorts the surnames. Then it takes all tiddlers tagged with client and with that surname in the 2_surname field and sorts them by given name and does this for each surname in order.

Tim Brown

unread,
Nov 25, 2015, 10:48:16 PM11/25/15
to TiddlyWiki
Hi Jed,

Thanks for the quick reply. I tried your suggestion but seem to be having an issue with the list operator.
Using the following, I get no results:
<$list filter="[tag[client]each[2_surname]sort[2_surname]]" variable=Surnames>
<$list filter="[tag[client]2_surname<Surnames>sort[1_givenname]]">
</$list>
</$list>

If I change the syntax to the following I do get results, but the first tiddler is duplicated:
<$list filter="[tag[client]each[2_surname]sort[2_surname]]" variable=Surnames />
<$list filter="[tag[client]2_surname<Surnames>sort[1_givenname]]" />

Any suggestions?

Thanks

Tim

Tobias Beer

unread,
Nov 26, 2015, 2:23:30 AM11/26/15
to tiddl...@googlegroups.com
Hi Tim,

First things first: I have made a little demo here for you to poke around:

I tried your suggestion but seem to be having an issue with the list operator.
Be sure to use the right terms, when you say "operator", we mostly think you refer to a filter operator.
It appears you meant to say "list widget", or ListWidget.

As for:
Using the following, I get no results:
<$list filter="[tag[client]each[2_surname]sort[2_surname]]" variable=Surnames>
<$list filter="[tag[client]2_surname<Surnames>sort[1_givenname]]">
</$list>
</$list>
You use an opening and a closing tag for the $list widget.
This makes the list widget assume that its contents are to be the item template.
Since you have nothing specified, it never actually outputs anything.

This won't work:
If I change the syntax to the following I do get results, but the first tiddler is duplicated:
<$list filter="[tag[client]each[2_surname]sort[2_surname]]" variable=Surnames />
<$list filter="[tag[client]2_surname<Surnames>sort[1_givenname]]" />
...because the two lists are not nested.

What you may think will work is:

<$list filter='[tag[client]each[2_surname]sort[2_surname]]' variable=Surname>

<$list filter='[tag[client]2_surname
<Surname>
sort[1_givenname]]'/>

</$list>

However, Jed forgot a tiny detail in the first filter.
We need to actually get the surname:

<$list filter='[tag[client]each[2_surname]get[2_surname]sort[]]' variable=Surname>


<$list filter='[tag[client]2_surname
<Surname>sort[1_givenname]]'/>

</$list>

Last but not least, I would not recommend adding numbers as prefixes to fields just to have them sorted in the editor.
There needs to be a better way. One would be to use a custom editor for you to edit client data.

Best wishes,

— tb

Tim Brown

unread,
Nov 29, 2015, 9:02:28 PM11/29/15
to TiddlyWiki
Hi Tobias,

Thanks for the info & samples. It really helped a lot.

>>Last but not least, I would not recommend adding numbers as prefixes to fields just to have them sorted in the editor.
>>There needs to be a better way. One would be to use a custom editor for you to edit client data.

Coincidentally that was the next issue I wanted solve. I'm trying to build a simple system to allow basic data entry of contacts and events with the contacts.
Ideally a custom screen triggered by a button on an existing tiddler that allows the creation of a new tiddler based on a template and populates the various custom fields I require.

I haven't managed to find any examples of a "custom editor". Can you provide any examples or links?

Also out of curiosity why do you recommend against the number prefixing other than the ugliness?

Thanks

Tim

Tobias Beer

unread,
Dec 1, 2015, 7:47:19 AM12/1/15
to TiddlyWiki
Hi Tim,

I haven't managed to find any examples of a "custom editor". Can you provide any examples or links?

Maybe this will point you in the right direction:


This one uses a form to create and also edit some sort of user tiddler,
although I actually find it a bit unintuitive, tbh. :D

Perhaps it gives a mild pointer as to how / where to start.

Other than that, take a look at the possible control widgets for editing, e.g.:
  • EditTextWidget
  • RadioWidget
  • SelectWidget
  • CheckboxWidget
While either storing the changes directly at that other tiddler,
or using a temporary tiddler to save changes to and then a...
  • ButtonWidget
...at the very end that takes all the input values from the control widgets
and writes them to whichever target tiddler(s).

Best wishes,

Tobias.

Tobias Beer

unread,
Dec 17, 2015, 7:27:39 PM12/17/15
to TiddlyWiki
Hi again Tim,


On Friday, 18 December 2015 01:24:59 UTC+1, Tobias Beer wrote:

Actually, correct me if I'm wrong, but sorting by multiple criteria is far simpler than initially thought.
All you need to do is reverse the order in your filter expresion, from weekest sort criteria to strongest, e.g.: 
 
{{{ [tag[Composers]sort[givenname]sort[surname]] }}}

Will have the output eventually sorted first by surname and then by givenname.
I have updated the doublesort demo accordingly: 
 
http://doublesort.tiddlyspot.com/ 

Best wishes,
Tobias.

James

unread,
Dec 18, 2015, 1:09:17 AM12/18/15
to TiddlyWiki
Hi All,

Just want to ask whether I can use the increment command in list filter?

Tobias Beer

unread,
Dec 18, 2015, 7:18:28 AM12/18/15
to TiddlyWiki
Hi James,
 
Just want to ask whether I can use the increment command in list filter?

Not sure this is the right spot to be asking.
Can you be more specific what it is you mean with "increment command"?

Best wishes,

Tobias.

Yaisog Bonegnasher

unread,
Mar 16, 2018, 5:20:39 AM3/16/18
to TiddlyWiki
Hi Tobias,

I used to make use of the "simple" doublesort, but I noticed that it doesn't work for me anymore. I'm currently on 5.1.15. I do not know when it stopped working.
Can you confirm this or is it my installation of TW5?

Best regards,
Yaisog

Aidan Grey

unread,
Jul 7, 2019, 2:56:32 PM7/7/19
to TiddlyWiki
Doesn't work for me anymore either.

Mark S.

unread,
Jul 7, 2019, 4:55:48 PM7/7/19
to TiddlyWiki
I don't think

sort[middlename]sort[givenname]

can be depended on to sort correctly. It might work occasionally , depending on your browser implementation. I think for
a reliable sort you have to use multiple list widgets, each nesting the inner one as shown in the original discussion.

My solution would be to make a button that would allow you to create a "sortby" field for all your entries, and then sort by that field. This would of course
mean that you have to remember to press the "Sort" button to refresh your list from time to time. For some reason, the idea that you have to
press a button before getting a result, something familiar to anyone who's ever had to refresh a web page or calculations in a spreadsheet,
seems to invoke pure horror among some individuals ;-)

Aidan Grey

unread,
Jul 7, 2019, 5:38:08 PM7/7/19
to TiddlyWiki
Thanks Mark,

So here's my code - what am I doing wrong? If I leave the second closure, I get the current tiddler listed 5 times (as below). If I take out the second closure (remove / from the second $list), I get nothing.

Also - do you (or anyone) know why an exclamation point doesn't sort before alphabet like everywhere else? Is there any way to force a specific item to sort first, like a custom sort list a la excel: ThisTiddler, a, b, c,. d...?


----

<table>
<tr><th>Path</th><th>Avatar</th><th>Colorway</th><th>Day</th></tr>

<$list filter='[tag[avatar]each[pord]get[pord]nsort[]]' variable=apath>
<$list filter='[tag[title]pord<apath>sort[title]]'/>

<tr>
<td> {{!!path}}</td>
<td><$link>{{!!title}}</$link></td>
<td>{{!!colorway}}</td>
<td>{{!!adate}}</td>
</tr>
</$list>
</table>

Mark S.

unread,
Jul 7, 2019, 6:39:20 PM7/7/19
to TiddlyWiki
There's a lot that's unclear here. What kind of value is "pord" ? It should be numeric, since you're doing a numeric sort. But I don't see
"pord" used in your output.

If you want your table rows to follow the result of the inner list, then you have to take out the / AND put a second </$list> after the table row structure.

BUT, you're not following Tobias' example. In the first list you filter by tag avatar, but in the second you're filtering by "title" tag. So the connection
between the two lists is a bit random. In Tobias' example, both inner and outer filters first use tag[avatar] .

If you only have a small number of avatars, you could just filter by tag[avatar] and use the list field to determine the sort order. The easy way to do this is to click on an avatar tag,
then drag and drop the listed tiddlers until you have the order you want. Now when you do a simple <$list filter="[tag[avatar]]">....</$list> it should sort per the
list.

Good luck!

Aidan Grey

unread,
Jul 7, 2019, 6:56:33 PM7/7/19
to TiddlyWiki
That's right, Mark - I don't want pord (which IS numeric) to be visible. It's only there for ordering.

When I use the two <$list>  tags, I get 5 items in the list, all links to the current tiddler (see A below)

The original I copied from earlier in this chain is:
<$list filter='[tag[client]each[2_surname]get[2_surname]sort[]]' variable=Surname>
<$list filter='[tag[client]2_surname<Surname>sort[1_givenname]]'/>
</$list>

2_surname = pord  AND  1_givenname = title

You're right that I got the filter wrong, so I fixed it (see black B below)  but still get the same result - current tiddler title 5x. What am I still doing wrong?

I found a solution, but it's labor intensive:

1. added this as new field: sord: {{!!pord}} {{!!title}}
2. used this filter:  <$list filter="[tag[avatar]] [tag[path]] +[!tag[noshow]] +[!sort[sord]]">
3. for the extra tiddlers I wanted to force to top, sord = {{!!pord}} 1

Not as labor intensive as manual method, but... still not ideal.



A -----------------------------------------------------------------------

<table>
<tr><th>Path</th><th>Avatar</th><th>Taalen Name</th><th>Colorway</th><th>Day</th></tr>
<$list filter='[tag[avatar]each[pord]get[pord]nsort[]]' variable=apath>
<$list filter='[tag[title]pord<apath>sort[title]]'>
</$list>
<tr>
<td> {{!!path}}</td>
<td><$link>{{!!title}}</$link></td>
<td> {{!!tname}}</td>
<td>{{!!colorway}}</td>
<td>{{!!adate}}</td>
</tr>
</$list>
</table>


B --------------------------------------------------------

<table>
<tr><th>Path</th><th>Avatar</th><th>Taalen Name</th><th>Colorway</th><th>Day</th></tr>
<$list filter='[tag[avatar]each[pord]get[pord]nsort[]]' variable=apath>
<$list filter='[tag[avatar]pord<apath>sort[title]]'>
</$list>
<tr>
<td> {{!!path}}</td>
<td><$link>{{!!title}}</$link></td>
<td> {{!!tname}}</td>
<td>{{!!colorway}}</td>
<td>{{!!adate}}</td>
</tr>
</$list>
</table>

Aidan Grey

unread,
Jul 7, 2019, 6:59:53 PM7/7/19
to TiddlyWiki
Oh! I forgot one weirdness.

In <$list filter="[tag[avatar]] [tag[path]] +[!tag[noshow]] +[!sort[sord]]">, I had to include the [!sort[sord]] because for some unknown reason, it's sorting backwards (alphabet, desc). This returned it to ascending alphabetical order.

Aidan Grey

unread,
Jul 7, 2019, 7:18:24 PM7/7/19
to TiddlyWiki
I lied - using sord didn't work at all. Still only sorts by title.

Mark S.

unread,
Jul 7, 2019, 8:00:13 PM7/7/19
to TiddlyWiki
Without having a sample of your data, it's hard to know. However, in (B) the second </$list> has to go below </table> . Where it is now it will do nothing.

Once you've moved it, it should sort by pord (numbers) first, and then inside of that grouping by titles.

Good luck!

Aidan Grey

unread,
Jul 7, 2019, 8:08:44 PM7/7/19
to TiddlyWiki
Figured it out. Both lists close at the end, otherwise the filter isn't maintained. In one variation,  I got a "List of Forms", one per actual item, which is what clued me in to the need for both list-closes to be at the end. The list of 5 was confusing me.


<table>
<tr><th>Path</th><th>Avatar</th><th>Taalen Name</th><th>Colorway</th><th>Day</th></tr>
<$list filter='[tag[avatar]each[pord]get[pord]nsort[]]' variable=apath>
<$list filter='[tag[avatar]pord<apath>sort[title]]'>
<tr>
<td> {{!!path}}</td>
<td><$link>{{!!title}}</$link></td>
<td> {{!!tname}}</td>
<td>{{!!colorway}}</td>
<td>{{!!adate}}</td>
</tr>
</$list>
</$list>
</table>
Reply all
Reply to author
Forward
0 new messages