Dynamic reordering of search results
I'd like for the search results to come out in a multi-column table where clicking on the table header resorts the results according to the custom field the column represents, like what the jQuery Tablesorter plugin does (http://tablesorter.com/docs/). I would just use the plugin, but I need have pagination as well, which means the Tablesorter plugin would only resort the items loaded on that particular page instead of from all the search results.
My question is whether Low Search can give paginated search results along with some links to resort the same results according to custom fields (orderby="custom_field_name"). I guess I'm asking if the order of the search results can be set dynamically by a URL segment or by some other means.
Sorry for the lack of brevity.
Replies
Jared Walters 23 Apr 2014 22:39
I figured this out shortly after. By using the URL tag and some conditionals based on the {low_search_param_name} tags, I can create links in the table header to reload the page with resorted results and dynamically make the link sort by asc or desc based on whatevers already been loaded. Something like this:
<table>
<thead>
<tr>
<th><a href="{if low_search_orderby == "custom_field_one"}{if low_search_sort == "asc"}{exp:low_search:url query="{segment_3}" orderby="custom_field_one" sort="desc"}{if:elseif low_search_sort == "desc"}{exp:low_search:url query="{segment_3}" orderyby="custom_field_one" sort="asc"}{/if}{if:else}{exp:low_search:url query="{segment_3}" orderby="custom_field_one" sort="asc"}{/if}">Custom Field One</a></th>
<th><a href="{if low_search_orderby == "custom_field_two"}{if low_search_sort == "asc"}{exp:low_search:url query="{segment_3}" orderby="custom_field_two" sort="desc"}{if:elseif low_search_sort == "desc"}{exp:low_search:url query="{segment_3}" orderyby="custom_field_two" sort="asc"}{/if}{if:else}{exp:low_search:url query="{segment_3}" orderby="custom_field_two" sort="asc"}{/if}">Custom Field Two</a></th>
</tr>
</thead>
<tbody>
etc...
Low 24 Apr 2014 11:19
Cool, glad you figured it out.