\define SortableFilters()
[tag[EBook]has[vendor]$(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%'>
Title
<$action-setfield sort_by='title'/>
<<ToggleDirection>>
</$button>
</th>
<th>
<$button class='tc-btn-invisible' style='width:100%;height:100%'>
Author
<$action-setfield sort_by='author'/>
<<ToggleDirection>>
</$button>
</th>
<th>
<$button class='tc-btn-invisible' style='width:100%;height:100%'>
Vendor
<$action-setfield sort_by='vendor'/>
<<ToggleDirection>>
</$button>
</th>
</tr>
<$list filter=<<SortableFilters>>>
<tr>
<td>
//<$link to={{!!title}}><$view field="title"/></$link>//
</td>
<td>
<$view field='author
'/>
</td>
<td>
<$view field='vendor'
/>
</td>
</tr>
</$list>
</table>
</$set>
I have noticed that, after sorting the table by a column, the secondary sort is always by title. So if I sort the list by vendor, the books are listed within that sort alphabetically. As this is a library index, it would be more appropriate if I could have the secondary sort default to the author field, rather than the tiddler titles.
Is there any way I might be able to change the behavior of the table, so that it will sort by a specific field rather than the title, after I have used the proper sort_by?
[tag[EBook]has[vendor]get[author]$(SortType)$sort{!!sort_by}]
<table>
<$list filter="[tag[Ebook]has[vendor]each[vendor]get[vendor]sort[]]">
<$list filter="[tag[Ebook]has[vendor]field:vendor<currentTiddler>sort[author]]">
<tr>
<td>
//<$link to={{!!title}}><$view field="title"/></$link>//
</td>
<td>
<$view field='author'/>
</td>
<td>
<$view field='vendor'/>
</td>
</tr>
</$list>
</$list>
</table>
book
to Ebook
.<table>
<$list filter="[tag[book]each[author]get[author]sort[]]">
<$list filter="[tag[book]field:author<currentTiddler>sort[date]]">
<tr>
<td>
//<$link to={{!!title}}><$view field="title"/></$link>//
</td>
<td>
<$view field='author'/>
</td>
<td>
<$view field='date'/>
</td>
</tr>
</$list>
</$list>
</table>
The most important concept to achieve sorts and subsorts is the use of nested list widgets. The filter in each list widget can select and sort. If the outer widget does the initial sort, the nested list can do the subsort.
this nesting can go multiple levels deep but quickly exhausts the data you have in each level.
Regards
Tony