How to sort multiple filtered list by several selects

Hello dear helpers,

several months working on my own ToDo-solution in TW I have now all basic functions working and the style I wanted.
But still I bring 2 things not to work: One of it is:

I have in my overview (“Meine ToDos”) several detail-widgets (overdue, today, tomorrow, and so on) and there inside the related filtered tasks.
On top of all these I have an additional filter with checkboxes and a text field. In this way I can filter the lists inside the details widgets in an additionally way.

I managed to sort the lists in the filter by several fields (sort by due, then by sortbereich, then by priority, and so on).
But I would like to be able to do this “sorting by several fields” over several select-widgets. For being able to do this in an easy fast way without the need to dive into the code.
In a “normal” list I have been able to do this by 4 select-widgets which write f.e. “due” in the field “sort1”, then

<$set name="sort1" value={{{[{!!sort1}]}}}>
<$set name="sort2" value={{{[{!!sort2}]}}}>
<$set name="sort3" value={{{[{!!sort3}]}}}>
<$set name="sort4" value={{{[{!!sort4}]}}}>

and then

<$list filter="[tag[Task]] +[sort<sort4>sort<sort3>sort<sort2>sort<sort1>]">
<div style="margin-left:1.5em;">
<li><$link><<currentTiddler>></$link> {{!!due}} - {{!!sortbereich}}</li></div></$list>

But that sorting does not work in my tasks-overview (“Meine ToDos”)- probably because of that additional filter. This additional filter is working over the tiddler “$:/config/TiddlyTools/FindTitles”.
I tried yesterday the whole day in one million ways without success, please help me now…

The link for testing it: https://tests.tiddlyhost.com/. The ToDo-related tiddlers are under the tab “ToDos” and there under the topic “ToDo Allgemein”. The tiddlers with related macros & so on are under the tab “Mein System” >tab “Weitere (Meine Plugins)”. And for the style-things under “TW-Style”.

Thanks a lot in advance! Noushka



Oh sorry, I saw now, that there is a strange popup behaviour in the tasks-overview. I really don’t know, how to remove that. But it only happens in the test-wiki, not in my own. And also it does not happen in the template “$:/core/ui/ListItemTemplate 2”, which you can find under the tab “Mein System” >tab “TW-Style”.
And I am also sorry for the ugly look. I did not tweak the main appearance-settings like in my own and also the details-widget does not take the styles from my stylesheet- in my own wiki it does.

1 Like

Hello @Noushka,
I use a filter to sort my books by different field, which I think could be changed for your needs. I used the script here from Scripts In Tiddlywiki by @Mohammad.
This is a very useful site with lots of coding / scripting examples.
I hope this file below, will help you.
I am sure that others will offer a solution soon.
Create a Doubly Sorted Table.json (2.4 KB)

2 Likes

An example book list to show sort order can be seen here

2 Likes

Hello Sunny,

thank you for your answer.
But sorry, maybe I didn’t explaine it good enough, this wasn’t my question. I am already able to double-sort (or more than 2 sortings) by writing the code. Then I get a “fixed” table- to realize another sort-option I have to dive into the code.

My question is instead, how to combine the easy sorting-way (by select-widgets, for another sorting-option there is no need to go into edit-mode, diving deep into the code. Instead only choosing with the select-widget. That’s it.

But how to combine this easy-sorting especially with the additional filter???
I don’t know how to try anymore, already tried over weeks now…

Hello @Noushka,
I understood your question but was offering a different method of sorting a table which may have helped, sadly it was (too simple) and of no use to you.
There was a similar question asked on Google Groups here which may be of some use. Maybe @Mark_S could offer some help as he mentioned the Sort Filter Run Prefix.
I am not sure if you know of this discussion mentioning a Filter Builder here which may be useful.

Hi @Sunny,
yes, my problem is the combination of my filters-plus-the-sorting-by-select.
Every single wish I am already able to build, some of them even in different ways.
But the combination of them …I am completely helpless…

I also already tried with that “:sort”-option mentioned in the googlegroup-thread, but also successless.
But that does not mean a lot- maybe I only made several small mistakes like missing a bracket here or putting there too many or wrong brackets or missing an empty space or similar… :joy: :woozy_face: :hot_face:

The filter builders- especially the first one- are really cool!! Thankyou for linking them :+1:- I haven’t seen them before and will keep them in my mind.

But still… they do not help me with my actual combining-solutions - problem :disappointed_relieved:.

Hi @Noushka,
sorry you have not solved your problem yet.
I can only suggest contacting @EricShulman and Keaton Lao for help.

1 Like

@Noushka

If you have implemented the multi sort, then instead of hardcoding criteria, use variables whose values come from a select widget!
That’s all.

Hello @Mohammad ,
thanks for your answer. Yes, I want to choose with a select widget. Yes, this is my wish.
But I don’t know, how to solve the combination with the already existing filter. How do I have to write that combination with the variables and the select-widget?

Or maybe, @EricShulman or @keaton could help?
Thank you a lot!

This is a simple example to show you how to use select value (here stored in a field).

This example shows a list of tiddlers tagged with HelloThere. User can choose a tiddler using the select widget.
The user choice is stored in mychoice field of current tiddler
The field then used in filter inside a list widget to show what tiddlers are tagged with user choice

  • open https://tiddlywiki.ocm
  • create a new tiddler with below content
  • from select widget choose a tiddler
  • see the result

<$select field=mychoice default="Examples">
<$list filter='[tag[HelloThere]]'>
<option value=<<currentTiddler>>><$view field='title'/></option>
</$list>
</$select>

''Show all tiddlers tagged with'' <$link to={{!!mychoice}}/>

><$list filter="[tag{!!mychoice}]">

</$list>

You may store your choice in a variable and then use it elsewhere. Just note the scope of the variable.

It was very awkward to edit your test wiki due to all the customizations you have made (and the fact that it is not written in English).

Even so, hiding the editor preview (which was “stealing the focus” on each keystroke) and turning off the autosave setting (which was periodically attempting to save changes back to TiddlyHost), I was able to work on your code to find a solution. Here’s my suggested changes:

First, when you get the selected sort values from the sort1, sort2, sort3, and sort4 fields, instead of using 4 separate $set widgets, you can use a single $let widget, like this:

<$let sort1={{!!sort1}} sort2={{!!sort2}} sort3={{!!sort3}} sort4={{!!sort4}}>

The above change doesn’t actually solve your problem, but it is a much more compact way to fetch the sortN field values.

Then, because each of the desired filters is dynamically constructed using $wikify, you need to add the extra sorting to the resultant filter syntax using something like this:

<$wikify name="filter" text="[suffix[ask]tagging[]<<is>>search:title[{{##text}}]] 
   +[sort[<<sort4>>]sort[<<sort3>>]sort[<<sort2>>]sort[<<sort1>>]]">

The result of the $wikify is a filter that looks like:

[suffix[ask]tagging[]search:title[]] +[sort[title]sort[prio]sort[sortbereich]sort[due]]

That should hopefully fix things.

-e

Hello @Mohammad ,
thanks for your answer. But still this does not help me, because it is not in the combination with my already existing filter-combination. And this combination-combination is my difficulty.

Hello @EricShulman ,
yeah, this is the kind of help I needed :slight_smile:
I am really sorry for the awkwardness :flushed:. Of course I guessed before, that it is not easy with all my customizations- but I thought, that it could maybe influence if things are working or not working, so I decided to put these customizations in the test-wiki. And the german language… It took me already a whole day to edit everything for making it more anonymous :wink: And I feareed already for that, that I maybe delete something essential by accident. To avoid such accident deleting or similar accidents I decided not to translate everything.
And also a big sorry for that I forgot to turn off the autosave on tiddlyhost. That I just forgot- should not have happened! And is now changed.

I copied your <letsort… and your <wikify name=“filter” … into the “Alles”-Details. And have been happy :smiley: . It works! Well yes, but only with the selection like it is and the 3. sort (Priorität/“prio”) is not sorted. This I do not understand- that some fields work and others not. So, Fälligkeit/“due” and Reihenfolge/“sortbereich” are working. But only with the selection like it is in the moment.

I tried to find any mistake or any missing or anything else. But found nothing…
I also tried to find out, how I can see the wikified filter-result. But I could not find out. Maybe I would be able to find the problem by myself, if I could see that result…

After the $wikify, put something like:

FILTER=<$text text=<<filter>>/><br>
1 Like

FILTER=<$text text=<<filter>>/><br>

Yep. The result- in the first line my selected values (1> 2> 3> 4) and in the second line the wikified result:

due> sortbereich> prio> title
FILTER=[suffix[ask]tagging[]search:title[]] +[sort[title]sort[prio]sort[sortbereich]sort[due]]

prio> sortbereich> due> title
FILTER=[suffix[ask]tagging[]search:title[]] +[sort[title]sort[due]sort[sortbereich]sort[due]]

prio> title> due> sortbereich
FILTER=[suffix[ask]tagging[]search:title[]] +[sort[sortbereich]sort[due]sort[title]sort[due]]

So, the mistake seems to lie in the sort1-field or has to do with it? It doesn’t matter, what I select, it wikifies always “due” as the first sorting-point.
I looked now if any empty space is missing or too much or any bracket or similar. But I could not find anything.

In your $select controls, the first one (field='sort1') has a param with tiddler="$:/config/TiddlyTools/FindTitles", which saves that selection in the specified tiddler, but the other $select controls (for sort2, sort3, and sort4) do not, so those lists default to saving their selection in the current tiddler.

Then, you retrieve the selected values from the current tiddler using:

<$let sort1={{!!sort1}} sort2={{!!sort2}} sort3={{!!sort3}} sort4={{!!sort4}}>

so the value for {{!!sort1}} doesn’t reflect the choice you made in the “sort1” $select list.

To fix this, just remove tiddler="$:/config/TiddlyTools/FindTitles" from the “sort1” $select list control.

-e

Yesss, that’s the solution :smiley: :smiley: :smiley: :smiley:!

Oh, I thought, that part tiddler="$:/config/TiddlyTools/FindTitles" is related to the whole select-part.
I tried it now in several ways with different filter and combined filters and different sortings and all together-combined. And everything worked :smiley: :smiley: :smiley:.
Thankyou!!!

Perhaps you could share a simplified example of the working code for others to see.

I have an idea that this could be e simplified a great deal using functions that reference the current settings within another function.

  • For me to demonstrate this it would be easier for me to work with an example of your final result than have to reverse engineer the whole topic.

Hello @TW_Tones ,
of course, gladly.
There are only a few things to mention & ask:

  • I do not completely understand / I am not sure how to understand you exactly.
    ** Do you mean, posting the code here in this thread in this way <code>="xy"{{!!transcluded}} <<and so on>>?
    ** Or do you mean, to simplify it in the tiddlyhost-testwiki?
  • Speaking for myself it is always at least very useful and often indeed just needed to see at least one working example in a wiki with a detailed explanation for beginners. But I cannot explaine -I am not able to explaine- why and how I build the code and all like it is.
  • Only the overview? Or also the tasks? Or also just everything related?
  • Unfortunately the overview is destroyed in the testwiki (in my own wiki not!) and I really do not have any idea, how to fix that. So ones cannot see the tasks- the most important in the overview.
  • I am still working on the whole. And would like to wait until that is completely finished.
  • Simplifying by reducing the choosable tags & sortings?
  • It would take time…

While I can’t speak for Tony, I would suggest that you create a small wiki with some data that is unrelated to your actual wiki, but easily understandable to a casual reader, then show how this type of multiple-field sorting could be used for that data.

I took the liberty of creating a small set of data that I think would work, some partial company personnel records: employees.json (27.2 KB) which you can download and drag onto an empty wiki.

The 85 records look like this:

age: 25
dept: Analytics Data Products
div: Technology and Operations
email: abaker@example.com
first-name: Alfredo
full-name: Alfredo Baker
last-name: Baker
location: Hartford CT USA
tags: Member
title: Alfredo Baker

(Note to the legal department :slight_smile:: Although this was originally extracted from a list of members of a chess club at GigantiCorp, where I work, it’s entirely anonymized and some data is purely invented.)

The last two fields are TW fields and not likely useful for sorting. But the remainder could be used as options for your various sorting criteria.

You can format the results as a table or a list of cards, or whatever seems useful. Then your UI should be able to demonstrate what happens when they sort by location, then age, then last name versus what happens when they sort by division, then department, then location. (Note that three sort fields would be plenty to demonstrate the behavior, even though your case requires four.)

Obviously there is no need to use this data. I will not be offended! But it’s this sort of technique which should make your sorting system obvious.