« Good Role Model The Church as a Business? »
Sorting Information
By Andy on 17 February 2006 early morningCategory: Web Design / Development
Until now, this site’s journal archive were sorted according to date in a reverse chronological order. That works nicely most of the time, but sometimes I’ve wanted to sort my archives alphabetically by the title, or sort numerically on the number of comments, which tells me what posts have been the most popular since I started journaling back in 2002.
The way I have done this on other sites such as the devotional archives on Lifetime.org, would be to make a new query to the database each time I want to sort the data. That worked, but it was slow, especially on large amounts of data, because the page had to reload (or refresh) each time the data was sorted.
I have recently been turned on to a new way of doing this that sorts the information without having to re-query the server’s database. I was talking to Brad Murray, lead programmer at Fellowship Church, the other day and he gave me a link to an extremely easy method of Javascript/client-side table sorting from Kryogenix.org
When I say it is easy, I mean it is really easy! Here are the steps:
Step 1
Download the javascript file, upload it to your web server, and then link to it from within the <head> tag of your HTML document:
<script src="sorttable.js"></script>
Step 2
Give your table of data a unique id:
<table id="sort1">
Step 3
Make sure your first row in the table is “header row” (<th>):
<tr>
<th>Date</th>
<th>Title</th>
<th>Author</th>
<th>Excerpt</th>
<th>Comments</th>
</tr>
That’s it. Thanks to Stuart Langridge of Kryogenix.org and Brad for sharing this with me.
commenting closed for this article