[TW5] Using sort order field, changing sort order

90 views
Skip to first unread message

Matthew Petty

unread,
Apr 10, 2016, 10:07:02 AM4/10/16
to TiddlyWiki
I have a bunch of tiddlers with a "sort_order" numerical field, so that when I list them, I can sort them in a custom way using nsort.
I then have two buttons next to each one to increment/decrement the sort order, which changes the list dynamically.

Is there any way to make a button which would increment one field, while decrementing the same field in the adjacent tiddler, which would have the effect of swapping the sort order of those two tiddlers?

So I have these tiddlers:

A (sort_order=1) [up] [down]
B (sort_order=2) [up] [down]
C (sort_order=3) [up] [down]

I click the [up] button on B, which decrements the sort_order for B and increments it for the tiddler with the "target" sort order value.
B is 2.
B wants to be 1.
A is 1.
Set A to 2.
Set B to 1.

This results in:

B (sort_order=1) [up] [down]
A (sort_order=2) [up] [down]
C (sort_order=3) [up] [down]

Clicking [down] on A incremembts the sort_order for A and decrements it for the tiddler with the "target" sort order value.
A is 2.
A wants to be 3.
C is 3.
Set C to 2.
Set A to 3.

Problems:
1. How to find the "adjacent" tiddler?
2. How to refer to the same field in the adjacent tiddler?
3. How to set the same field in both the current and adjacent tiddlers, one incremented, the other decremented (or vice-versa)

I'm just brainstorming here, but a list with a changeable sort order would be very useful.

c pa

unread,
Apr 11, 2016, 1:29:58 AM4/11/16
to TiddlyWiki
Matthew,

Here's an example of how to do this. I did it as a table. To make it work like you want you'll have to edit the html in the example.

http://cpashow.tiddlyspot.com/#Sort%20List

Matthew Petty

unread,
Apr 18, 2016, 3:17:31 PM4/18/16
to TiddlyWiki
Thank you! I've been working with this, and I think I have it the way I want it! I'll post more later.
One key thing is to use 'nsort' instead of 'sort' so that it sorts numerically instead of alpabetically. That way when you have more than 9 items, they sort correctly.
Reply all
Reply to author
Forward
0 new messages