Page 1 of 1

ListIt2: How to let user choose sorting order of output?

Posted: Mon Feb 10, 2014 1:57 pm
by emgaron
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:

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>
The page the list is displayed on looks like:

Code: Select all

{ListIt2People summarytemplate="Telefoonlijst"}

[...other 'static' content...]
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

Re: ListIt2: Let user choose sorting order of output

Posted: Mon Feb 10, 2014 2:50 pm
by velden
I'm not sure the ordering parameter of LI2 works well all the times (e.g. in case of pagination) but if you say it works in your template:

Try CGSimpleSmarty module, read the help (from Modules page) and use the {module_action_link} tag.

You could also consider using a client side solution with jQuery. It would probably give a user friendly way of sorting and doesn't cost any server side resources.

Re: ListIt2: How to let user choose sorting order of output?

Posted: Mon Feb 10, 2014 3:20 pm
by Stikki
Howdy,

Goran just implemented this into backend.

http://fooplugins.com/footable-demos/

Fairly simple and responsive table plugin to setup.

I suggest you use it with your intranet. It uses Javascript to sort current view.

If you wanna have actual frontend filters, use search action.

I suggest you to upgrade to latest as it has way more fetures than 1.3.2 one.

Re: ListIt2: How to let user choose sorting order of output?

Posted: Mon Feb 10, 2014 4:39 pm
by emgaron
Stikki wrote:Goran just implemented this into backend.

http://fooplugins.com/footable-demos/
[...]
Hm, that looks promising, though I'll have to find out whether/how it works standalone - out intranet has no external connections whatsoever, so no linking to googleapis or suchlike. I haven't looked into this at all so far... I'll try updating ListIt2 first and see where that gets me - thanks for the hint!

Regards,
Thomas

Re: ListIt2: How to let user choose sorting order of output?

Posted: Mon Feb 10, 2014 5:23 pm
by emgaron
emgaron wrote:I'll try updating ListIt2 first and see where that gets me
Well, that gets me nowhere, as that particular server still uses PHP5.2, which isn't supported anymore. Looks like I'll have to put this one on ice for now. ::)