HowTo: In table filter currentTiddler for prefix-fields & sort by their values

Hello @all,

I have a problem with table and with sorting the displayed cells.

I have equipment-tiddlers with several fields named in a pattern:
GewKl-orange-lang-8
GewKl-rot-lang-7
GewKl-orange-u-1+8
GewKl-rot-u-2+8
and so on.

These fields have number values.

:red_question_mark: Now I want to display these fields with their values in the tiddler, but sorted by their values.
Sorting is now like this (>Nr. means field-value):
GewKl-orange-lang-8 >5
GewKl-orange-u-1+8 >3
GewKl-rot-lang-7 >4
GewKl-rot-u-2+8 >1

But I want it like this:
GewKl-rot-u-2+8 >1
GewKl-orange-u-1+8 >3
GewKl-rot-lang-7 >4
GewKl-orange-lang-8 >5

I could not try anything, because I do not have any idea, not at all. Also Googling did not help.

:red_question_mark: And my other problem is probably a table-related one (?): The first filter works as intended (the left 3 cells with “GewKl-rot-lang”), but the second filter with “GewKl-rot-u” does not work. It shows only 2 fields, but them over all cells. And also the headers are broken.

I tried in several ways re-arranging the html-table-tags, re-arranging /replacing /removing things inside the filter. All with no success.

https://tests.tiddlyhost.com/ >The relevant tiddler is under the tab “:flexed_biceps:”, called “Widerstandsband”.

I hope, I have described it in a way, that you can understand & help me with this?

Hi @Noushka! Is your demo wiki up to date? I took a quick look at the " Widerstandsband" tiddler, but I didn’t see any tables.

However, if the filter you’re using to generate your table rolls looks something like this one from your “Choose the Equipment” filter…

[<equipmentGewählt>fields[]prefix[Gew]]

You can try using the :sort filter run prefix. For example:

[<equipmentGewählt>fields[]prefix[Gew]] :sort:number[<equipmentGewählt>get<currentTiddler>]

In a :sort filter run, <currentTiddler> has a special value: it refers to each output of the previous filter run. In this case, that’s each field with the prefix “Gew”. So the :sort filter run is effectively saying…

  • For each field with the “Gew” prefix present on the tiddler <<equipmentGewählt>>
  • Get the value of that field on the <<equipmentGewählt>> tiddler, then…
  • Sort the field names based on their numeric values.

:laughing: :face_with_spiral_eyes: Uhhh sorry, forgot to save…
Now, it is saved, they should be displayed now…

I’ll try your suggestion- thanks!

Tried- but does not work.
You could not know it, because previously forgetting to save- in this filter is now several times after each other , so I think- this is just breaking eachother. Because I do this filtering on the currentTiddler itself. Well, I will try to replace the first with something like [{!!title}] & experiment. But I’m afraid, that won’t do the job.

The filter is now like this:

<$list filter="[<currentTiddler>fields[]prefix[GewKl-rot-lang]] :sort:number[<currentTiddler>get<currentTiddler>]" variable="GewKl-lang">
 <tr>
    <td><<GewKl-lang>></td>

Okay, I can see it now. :slight_smile:

I don’t entirely understand the information being conveyed by the table, but if these are separate values, you probably don’t really want the nested lists — otherwise, you’re iterating one set of values over the other, and that’s causing the header mismatch you noticed. I’d recommend trying something like this…

<style>
th.red { background: #FF2E2E; }
</style>

<table>
	<tr>
		<th class="red">Rotes Band<br>als langes Band</th>
		<th class="red">GewKl</th>
	</tr>
<$list filter="[<currentTiddler>fields[]prefix[GewKl-rot-lang]] :sort:number[<..currentTiddler>get<currentTiddler>]" variable="GewKl-lang">
 	<tr>
		<td><<GewKl-lang>></td>
        <td><$text text={{{ [<currentTiddler>get<GewKl-lang>] }}} /></td>
	</tr>
</$list>
	<tr>
		<th class="red">Rotes Band<br>als U-Band</th>
		<th class="red">GewKl</th>
	</tr>
<$list filter="[<currentTiddler>fields[]prefix[GewKl-rot-u]] :sort:number[<..currentTiddler>get<currentTiddler>]" variable="GewKl-u">
	<tr>
		<td><<GewKl-u>></td>
        <td><$text text={{{ [<currentTiddler>get<GewKl-u>] }}} /></td>
	</tr>
</$list>
</table>

Or if you want to present the sections side by side…

<style>
table.inline-block { display: inline-block; vertical-align: top; }
th.red { background: #FF2E2E; }
</style>

<table class="inline-block">
	<tr>
		<th class="red">Rotes Band<br>als langes Band</th>
		<th class="red">GewKl</th>
	</tr>
<$list filter="[<currentTiddler>fields[]prefix[GewKl-rot-lang]] :sort:number[<..currentTiddler>get<currentTiddler>]" variable="GewKl-lang">
 	<tr>
		<td><<GewKl-lang>></td>
        <td><$text text={{{ [<currentTiddler>get<GewKl-lang>] }}} /></td>
	</tr>
</$list>
</table>
<table class="inline-block">
	<tr>
		<th class="red">Rotes Band<br>als U-Band</th>
		<th class="red">GewKl</th>
	</tr>
<$list filter="[<currentTiddler>fields[]prefix[GewKl-rot-u]] :sort:number[<..currentTiddler>get<currentTiddler>]" variable="GewKl-u">
	<tr>
		<td><<GewKl-u>></td>
        <td><$text text={{{ [<currentTiddler>get<GewKl-u>] }}} /></td>
	</tr>
</$list>
</table>

In either case, note that I’m using :sort:number[<..currentTiddler>get<currentTiddler>] rather than :sort:number[<currentTiddler>get<currentTiddler>]. This issue didn’t come up in my earlier code because I used a named variable <equipmentGewählt>, but since you’re using <<currentTiddler>> here, we need to distinguish between the original value of <<currentTiddler>> (outside the filter) and the new value of <<currentTiddler>> as assigned by :sort. <<..currentTiddler>> (note the two periods!) lets us access the original value of <<currentTiddler>> — that is, the tiddler itself, not the field name.

Cool :+1: , that’s it !

Yes, I guessed, that all these <currentTiddler> after another could not work. I just didn’t know this two points before. And still I do not completely understand the code now. F.e. why is the last <currentTiddler> again working. But probably that is a better idea for tomorrow midday or something.

And I saw, you made 2 tables of it (“lang” & “u”), not all of them in one table. I am fine with it- that makes it easier for me to understand things and maybe later in some years or so being able to change something.

And additionally I let the fieldname being more readable displayed with <$text text={{{ [<GewKl-u>removeprefix[GewKl-rot-]] }}} />

Thank you!!