ListIt2: How to let user choose sorting order of output?
Posted: Mon Feb 10, 2014 1:57 pm
I'm using ListIt2 (1.3.2 under CMSMS 1.11.4) on our intranet website to provide a list with names and telephone numbers. The template called "Telefoonlijst" I use for that looks like:
The page the list is displayed on looks like:
This is all working very well so far. However, one of our users approached me with the question whether it would be possible to change the list so that he could e.g. click on one of the table headers and the list would then be sorted by that field instead of by "Naam" (which is the default). I've been mulling about this for quite some time (including a search through this forum) but I'm clearly not doing this often enough - I just can't come up with an idea how to implement this... ...which I find annoying, as I have the suspicion that it is quite simple and I'm just missing something...
Sorting as such (e.g. by adding a suitable "orderby" parameter to the template call) works fine, so maybe I could just make each table header a link to the page itself with a suitable "sort parameter" which then gets passed on to the template call - but how?
Any hints, pointers and RTFM-slappings are most welcome!
Thanks in advance,
Thomas
Code: Select all
<table><tbody>
<tr>
<th>Nummer</th><th colspan="2">Naam</th><th>E-mail adres</th><th>Mobiel</th><th>Groep</th>
</tr>
{foreach from=$items item=item}
{if !empty($item->fielddefs)}
<tr>
<td>{$item->telefoon|cms_escape}</td>
<td><a href="{$item->url}">{$item->achternaam|cms_escape}{if $item->tussenvoegsel != ''}, {$item->tussenvoegsel|cms_escape}{/if}</a></td>
<td><a href="{$item->url}">{$item->voornaam|cms_escape}</a></td>
<td>{$item->e_mail|cms_escape}</td>
<td>{$item->mobiel|cms_escape}</td>
<td>{$item->category_name|cms_escape}</td>
</tr>
{/if}
{/foreach}
</tbody></table>
Code: Select all
{ListIt2People summarytemplate="Telefoonlijst"}
[...other 'static' content...]
Sorting as such (e.g. by adding a suitable "orderby" parameter to the template call) works fine, so maybe I could just make each table header a link to the page itself with a suitable "sort parameter" which then gets passed on to the template call - but how?
Any hints, pointers and RTFM-slappings are most welcome!
Thanks in advance,
Thomas