[TW5] Sorting Ascending and Descending

194 views
Skip to first unread message

reakt...@gmail.com

unread,
Dec 7, 2016, 1:53:43 PM12/7/16
to TiddlyWiki
A while back I made a post about creating tables and sorting the data by column header. One of the suggestions was to check out an example by Jed, outlined below. This works for the most part but what I'd like to do be click the header a second time to reverse the sort order.

Is something like this possible? I've tried using a reveal widget however, I was not successful. I'm not sure if this is even possible at the moment, let alone if I'm using the right syntax. 

<table>
<tr>
<th>
<$button class='tc-btn-invisible' style='width:100%;height:100%'>
Plugin name
<$action-setfield sort_by='name'/>
</$button>
</th>
<th>
<$button class='tc-btn-invisible' style='width:100%;height:100%'>
Plugin maintainer
<$action-setfield sort_by='maintainer'/>
</$button>
</th>
</tr>
<$list filter='[tag[Plugin twCard]has[name]has[maintainer]sort{!!sort_by}]'>
<tr>
<td>
<$view field='name'/>
</td>
<td>
<$view field='maintainer'/>
</td>
</tr>
</$list>
</table>


Jed Carty

unread,
Dec 7, 2016, 2:09:07 PM12/7/16
to TiddlyWiki
It is doable, and I think I made a version that let you do what you want. Let me see if I can find it anywhere.

Jed Carty

unread,
Dec 7, 2016, 2:25:41 PM12/7/16
to TiddlyWiki
If I have made it I don't have it anywhere obvious. The idea is that you make the filter in a macro and have the buttons toggle between using sort and !sort. This works on inmysocks.tiddlyspot.com

\define FilterThingy()
[tag[Plugin twCard]has[name]has[maintainer]$(SortType)$sort{!!sort_by}]
\end

\define ToggleDirection()
<$list
    filter
='[<currentTiddler>sort_type[!]]'
    emptyMessage
="""<$action-setfield sort_type='!'/>"""
>
   
<$action-setfield sort_type=''/>
</$list>
\end

<$set
    name=SortType
    filter='[<currentTiddler>get[sort_type]]'

>
    <table>
        <tr>
            <th>
                <$button
                    class='tc-btn-invisible'
                    style='width:100%;height:100%'
                >
                    Plugin name
                    <$action-setfield
                        sort_by='name'
                    /
>
                   
<<ToggleDirection>>

               
</$button>
            </
th>
           
<th>
               
<$button
                   
class='tc-btn-invisible'
                    style
='width:100%;height:100%'
               
>
                   
Plugin maintainer
                   
<$action-setfield
                        sort_by
='maintainer'
                   
/>

                   
<<ToggleDirection>>
               
</$button>
            </
th>
       
</tr>
        <$list
            filter=<<FilterThingy>>

        >
            <tr>
                <td>
                    <$view
                        field='name'
                    /
>

               
</td>
                <td>
                    <$view
                        field='maintainer'
                    /
>
               
</td>
            </
tr>
       
</$list>
    </
table>
</$set>


now my head hurts and I am going to go lie down. I need to remember to add this to my tables macros sometime.

Stephen Kimmel

unread,
Apr 4, 2017, 9:02:49 AM4/4/17
to TiddlyWiki
Nudge nudge.



now my head hurts and I am going to go lie down. I need to remember to add this to my tables macros sometime.

I would very much like to see you make this modification.

And for what it is worth, I use your table macros routine all the time.
Reply all
Reply to author
Forward
0 new messages