Last updated October 12, 2011. Created by hunmonk on November 17, 2006.
Edited by hjc1710, Leksat, bekasu. Log in to edit this page.

With Drupal 5.0 and beyond, it is now possible to provide independent sorting of tables when they appear on the same page.

This is accomplished by inserting a unique label for each table in both the tablesort_sql and theme('table'... calls for each relevant table.

For example, suppose you had two sortable tables on a page, one a list of users, and the other a list of nodes. To make each table sortable independently, you would do something like:

For the user table:
...

$user_sort = tablesort_sql($header, NULL, 'user');

...and then in the user table theme call...
$output = theme('table', $header, $rows, array('class' => 'some-class'), NULL, 'user');

For the node table:
...

$node_sort = tablesort_sql($header, NULL, 'node');

...and then in the node table theme call...
$output = theme('table', $header, $rows, array('class' => 'some-class'), NULL, 'node');

Note that for each table, the label you use for tablesort_sql and theme('table'... must be identical for the independent sorting to be handled properly.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

I'm quite positive this is just not true. It is based off a proposed feature request, see here for the proposal. The name of the user who proposed it is: hunmonk, he is also the original author of this page. I imagine he threw this up thinking Dries would ok his submission and let us sort multiple tables on the same page, so he gave us an early "tutorial" page. If you follow the linked proposal, Dries says he doesn't like sorting multiple tables on the same page and lists some reasons why he thinks Drupal should not have this feature.

So, I'm sure this documentation was added ages ago and forgotten about.