Connect with me
Search
Twitter Feed
Navigation
« 401.1 Unauthorized - IIS & WCF using custom host headers and host entry | Main | Performance Point Server Error - "The Unattended Service Account"... »
Wednesday
Apr282010

Client side table sorting and filtering with jQuery tablesorter

Ran into an awesome jQuery plugin today while trying to find a quick way to add filtering and sorting to a table on the client machine rather than on the server side. It’s called TableSorter.

You can easily enable client side filtering, sorting and paging with a few lines of javascript and a multitude of options to customize it to your needs.

Here’s a demo. You can click on the headers to sort or type into the textbox to filter by FirstName or LastName.

Search:

Last Name First Name Owing
King Justin $22.00
Liu John $35.00
Truong Michelle $100.00
Gfader Peter $50.00

 

This was implemented as follows:

<table id="myTable" border="1">
    <thead> 
        <tr>
            <th>Last Name</th>
            <th>First Name</th>
            <th>Owing</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>King</td>
            <td>Justin</td>
            <td>$22.00</td>
        </tr>
        <tr>
            <td>Liu</td>
            <td>John</td>
            <td>$35.00</td>
        </tr>
        <tr>
            <td>Truong</td>
            <td>Michelle</td>
            <td>$100.00</td>
        </tr>
        <tr>
            <td>Gfader</td>
            <td>Peter</td>
            <td>$50.00</td>
        </tr>
    </tbody>
</table>

Then add the following to your jQuery’s document.ready function.

  jQuery(document).ready(function() {
    $("#myTable")
      .tablesorter({debug: false, widgets: ['zebra'], sortList: [[0,0]]})
      .tablesorterFilter({filterContainer: $("#filter-box"),
                          filterClearContainer: $("#filter-clear-button"),
                          filterColumns: [0,1],
                          filterCaseSensitive: false});
  });

References (1)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    Response: amika flat iron
    [...]Client side table sorting and filtering with jQuery tablesorter - Blog - EricPhan.info[...]

Reader Comments (2)

Check is in the mail :P

29 April 2010 | Unregistered CommenterJustin King

Great blog Eric. Table sorter/search is awesome!!!

05 May 2010 | Unregistered CommenterAnthony

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>