Unobtrusive Table Sort Solution
Looking for a good dynamic table sorting solution? We have been playing with a few out there including spry and well we think we have found a goodie.
We thought we would take a sec to explain how we integrated it into an app. Whats great about this implementation is it is totally unobtrusive and could be implemented site-wide with ease.
We included the two javascript files that you can downloaded at the bottom of http://www.frequency-decoder.com/ blog entry.
The first script can run without the second script if you don't require page numbering however i would highly recommend it.
<script type="text/javascript" src="js/pageNumber.js"></script>
Now simply create your table and its all about the class, we have tested with more than one table and it was absolutely fine..
Its all about the class which its pretty clever. To breakdown what we have worked out each parameter means
- sortable(pretty clear) - onload-3-reverse (sort column three in reverse)
- rowstyle-alternative (pretty clear)
- paginate-7 (how many records to show on a page)
Now simply create the rest of your table defining which columns you want to sort by
<tr>
<th class="sortable">Name</th>
<th class="sortable">Level</th>
<th class="sortable">Username/Email</th>
<th class="sortable">Password</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<cfloop query="qgetUser">
<tr>
<td>#qgetUser.lastname#, #qgetUser.FirstName#</td>
<td>#oU.getLevel(qgetUser.level)#</td>
<td>#qgetUser.email#</td>
<td>#qgetUser.password#</td>
<td><a href="?edit=#qgetUser.uid#">Edit</a></td>
<td><a href="?deleteUser=#qgetUser.uid#">Delete</a></td>
</tr>
</cfloop>
</tbody>
</table>
We have done some load testing and as the author explains there are a number of things that will slow this down including having ALOT of records. However the wait was totally acceptable with a thousand or so records. Hopes this helps and if all goes well and we can find sometime look forward to an update to our datagrid solution.
