New jQuery Plugin - tableFilter() (Beta 1)

Posted by daemach on May 07, 2007

tableFilter is a filtering, sorting, paging, striping plugin with pretty much no configurability at the moment ;) Given a simple table with a header row, it tries to handle everything automatically. The main feature of this plugin is the ability to sort and/or filter on multiple columns by selecting additional columns using ctrl-click.

Usage: $(’yourtable’).tableFilter();

Caveats:

  • IE sucks. the plugin is nearly twice as fast in Firefox
  • I haven’t even seen a Mac in at least 5 years so you can forget about Safari support unless someone else would like to pitch in. If there is any interest in this I might consider testing in Opera.
  • I went for speed over lightness of code. 25K uncompressed though it looks like it will pack to 10K.
  • Please remember that this is an early beta. New things are coming.

Credits:

  • Jörn Zaefferer for prototype extensions, giving me some insight into object theory.

  • Mike Alsup for logging function and general excellence in coding.

  • Matt Kruse for table sorting theory and general excellence in coding.

  • The jQuery dev list for putting up with my occasionally bone-headed questions.

View the demo here

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. justin Mon, 07 May 2007 15:20:37 Eastern Daylight Time

    Hey Guys,

    great work on the table pager/sorter/filter!!

    just wondering is there any plans to be able to load the unshown data (ie. data on the second page etc.. ) only on demand - hopefully making the initial page load of a large page quicker

    refer http://dowdybrown.com/dbprod/rico2/examples/php/ex3.php for example

    Cheers

    Justin

  2. daemach Mon, 07 May 2007 15:28:16 Eastern Daylight Time

    I wrote this to make existing tables more usable. Ajax paging is doable, but it depends a lot on what back-end technology you’re using. If there is a big need for this I’m not opposed to taking a look at it.

  3. Christopher Jordan Mon, 07 May 2007 16:12:14 Eastern Daylight Time

    The demo looks real nice, Daemach! Very cool! :o)

    Cheers,
    Chris

  4. daemach Mon, 07 May 2007 16:13:53 Eastern Daylight Time

    Thanks Chris :)

  5. Aaron Heimlich Mon, 07 May 2007 18:29:30 Eastern Daylight Time

    This is some really impressive stuff!

    Also, just so anybody reading this is aware, jQuery 1.1.3 (not out yet, but will be soon) should be able to correctly handle cols and colgroups, so daemach’s patches are only necessary temporarily.

  6. daemach Mon, 07 May 2007 18:33:51 Eastern Daylight Time

    Thanks Aaron -

    And for those reading this, the dev list has been very active and the bugs I patched have already been fixed. They just want to make sure it’s perfect before releasing so it shouldn’t be long now.

  7. Lance Tue, 08 May 2007 17:32:55 Eastern Daylight Time

    The table looks very impressive. I am wondering, does it / will it have the functionality so that a function can be called and the row ID passed to it when a table row is clicked? Can data in a cell be formatted as a link (most likely done in the data file I suppose)?

    Thanks Lance

  8. daemach Tue, 08 May 2007 17:42:10 Eastern Daylight Time

    I wasn’t planning on adding any per-row functionality, but I’m willing to consider it if you can explain what you want to accomplish with this functionality. tableFilter just wraps your existing table, so if you wanted to add links, row event handlers or anything else you could do it outside tableFilter.

    I am working on a plugin architecture now that will allow extending the base functionality. The first plugin is an aggregation function that will calculate sum/avg/min/max values on filtered numeric columns. If you have ideas for other functionality, let me know so I can work in the handlers.

  9. Lance Wed, 09 May 2007 07:19:01 Eastern Daylight Time

    Regarding row functionality. Function example. I’m currently doing a site where a table of data from a DB is created. Each row has an ID. Good to offer the choice of the row number or a column cell value that may be a key for something. When the user clicks on a row, a function is called and the ID from the row is passed to that function. In my case the ID is a DB primary key. At this point the coder can write anything in that supplied function. In this example, I’m using the passed key to open a new window that displays a lot more information about the listing that was selected in the table. The passed key is used in a DB query to populate the new window.

    So, a lot can be done if you provide an empty function call on the click of a row and offer to pass either the row number or a given row cell value. Food for thought.

  10. daemach Thu, 10 May 2007 07:48:11 Eastern Daylight Time

    Thanks for the comments. Please note that tableFilter is just a “wrapper” for your table. You can easily use jQuery to add the functionality you’re looking for like this:

    $(’#yourTable’).tableFilter().children(”tr”).bind(”click”,function(){ //this.id or $(this).attr(”id”) will give you the ID of the row. this.cells[n] or $(this).children(”td”) gives you all the cells in this row});

  11. xavier Tue, 15 May 2007 03:46:52 Eastern Daylight Time

    Hi,

    Some columns might contains “special” types of datas, that you don’t sort by alphabetical order (eg MM-DD-YYYY). Would it be possible to set a class in the header to define how to sort it ?

    Otherwise, I love the filter solution, very elegant ! For the column that provide a fixed set of options (eg the country one), would it be possible to have a select field instead of the free form one ?

    Brilliant !

    X+

  12. daemach Tue, 15 May 2007 07:28:15 Eastern Daylight Time

    Unfortunately, I have to do some magic to be able to sort by multiple columns, so I’m forced to sort everything alphabetically - even numbers and dates. I convert the data to a special format for sorting during the parsing stage.

    By default, if a column has 6 unique values or less you get a drop-down, otherwise you get a text field. I’ve increased that to 10 unique values in the latest version, but you will be able to override that if you wish.

    I’m glad you like it - more coming soon.

  13. xavier Wed, 16 May 2007 07:33:46 Eastern Daylight Time

    Hi,

    Ok, got if for the drop-down, and good idea for the override.

    I’m not understanding your code, but would it be possible to add some custom code between the “get the value from the cell” and “feed it to the sort machine” ?

    Then sorting by number, date, source of the image… could just be about putting the right filter that converts between DD-MM-YYYY to YYYYMMDD for instance.

    That’s one of the benefits of not seeing the code: everything looks so simple. The downside, of course, is that you look stupid with meaningless suggestions ;)

    X+

  14. daemach Wed, 16 May 2007 07:56:49 Eastern Daylight Time

    The code is pretty complex, though some of that is due to trial-and-error testing. I don’t have a programming background and I’m new to oop, so the code isn’t very elegant. It has improved somewhat in the latest version.

    Parsing/sorting is handled using dataTypes. You could create another dataType definition which allows you to handle the source any way you need to.

  15. Oscar Thu, 24 May 2007 03:06:22 Eastern Daylight Time

    The code is wonderful.

    Could be nice to add a function to print friendly the content of the table

    Cheers,
    Oscar

  16. jebe Mon, 28 May 2007 05:13:49 Eastern Daylight Time

    When the first stable version will be published?

  17. daemach Tue, 29 May 2007 21:43:32 Eastern Daylight Time

    Well it’s stable right now as long as you’re using a pretty simple table. As soon as I can get to it is the real answer. This is a side project for me unfortunately, so I can’t devote as much time to it as I would like.

  18. Sharath Wed, 20 Jun 2007 14:00:28 Eastern Daylight Time

    It might help if you guys could let me know how I make this work with my table. I’ve got an asp page. I’ve tried other tablefilters but found yours very appealing. For some reason not able to make it work with my table. What are the things I need to change to make it work with my table?

  19. daemach Fri, 22 Jun 2007 12:36:38 Eastern Daylight Time

    Take a look here for some basic tips: http://ideamill.synaptrixgroup.com/?page_id=16

    Make sure you’re using the version of jquery that I included with the zip. Until 1.1.3 is released, it’s the only version that will work properly with this plugin.

Comments