This patch adds Ajax-based tablesorting to tablesort.inc. Note that this is /not/ client-side sorting, which isn't that useful in Drupal as most sortable tables are paged. Of course, given that it still requires a round-trip to the server, the biggest advantage is in visual usability, as only the table itself changes and not the entire page.
The way this is accomplished will probably strike you as very elegant, or very dirty ;). In order to avoid patching up every instance of a sortable table and providing a custom Ajax menu callback for each, I made it so that inside theme('table'), the tablesort can cause the table to be printed immediately and PHP to quit. This is triggered by the GET variable 'tablesort', when set to the table's id.
So, the Ajax HTTP request visits the exact same page as the original page, it only adds something to the URL which triggers this special behaviour.
It works really well. In fact, the id-per-table wouldn't be necessary if we restricted ourselves to one sortable table per page.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | jstablesort_0.patch | 13.25 KB | Steven |
| jstablesort.patch | 12.93 KB | Steven |
Comments
Comment #1
Steven commentedMissed a table in statistics.module ;).
Comment #2
Thox commentedI haven't tested the patch, only glimpsed through it for now.
The JS-side seems fine. I'm a little curious why tablesortAutoAttach() does all the hard work, I imagined the tablesort object could do that for itself.
+1 on the concept.
Comment #3
Steven commentedThe structure just mimics the existing stuff really (like autocomplete.js): the autoattach deals with seeking out suitable targets and installing the event handler. The tablesort object is just there to provide a persistent data storage for handling the asynchronous request.
I suppose once we've found a table we could create a tablesort object and then seek out the relevant links and header cells in there, but I don't see a problem with doing that in the autoattach either.
Comment #4
m3avrck commentedTried it out on latest HEAD, patch works great!
However, the little 'throbber' graphic... with the browser maximized, the graphic was hard to notice on a quickly loading page, since the graphic was so far to the right wasn't easily noticeable what that little 'flash' thing was. I think it would be more usability to move this graphic so that is just right of the text being clicked on (where the up and down arrows are for showing if that is sorted or not). That would make it much more clear as to what the little grahpic is actually about.
Otherwise, I say this is ready to commit, and +1 after the throbber issue is fixed :)
Comment #5
m3avrck commentedJust for clarification, where I am clicking with the mouse (on the actual text to sort the column) I would expect to see a little 'loading' icon there. Right now that little icon is way *toooooo* far away to make that simple connection :)
Comment #6
m3avrck commentedFor further clarification and after more testing, this is only a problem where columns take up much more of the page width, for example on the logs page and clicking on the 'messages' column. However, playing around with the CSS more I'm not too sure if there is a suitable fix for this, so I'll give this patch a +1 and it works great. Degrades well for users with Javascript disabled.
Comment #7
Bèr Kessels commentedI tried this in konqueror 3.4.1 and it works great. I cannot get to test two tables on one page, for I have no clue where (if! ever!) that occurs.
steven. A small suggestion for these kind of JS specific patches: set up a page solmewhere where people can test its behaviour. The reason I did not test the JS upload, was because I had no time to set up a meaningfull drupal site with that patch, only to see if konqueror could deal with it.
I doubt a lot of people can reasd JS well enough to comment on he code, but peolpe can then easily visit a page to see if it works with Their Strange Browser.
Comment #8
dries commentedI tried this patch but I don't see a throbber? My natural reaction is to check Firefox's throbber. Also, I'm not convinced it is a good idea to trade usability for performance.
Comment #9
Bèr Kessels commentedThe clients 'busy' notification not reacting on AJAX is a common usability issue with AJAX. One of many. the back button not working is another *mayor* one. All in all, AJAX is still far from mature and even further from perfect. Still, it serves Drupals usability quite well.
More about AJAX usability drawbacks here: http://sourcelabs.com/ajb/archives/2005/05/ajax_mistakes.html and http://www.baekdal.com/articles/Usability/XMLHttpRequest-guidelines/
Comment #10
jose reyero commentedCouldn't we just provide this as a library to be used by themes, and then leave the default theme functions free of this stuff?
Comment #11
Bèr Kessels commentedI really like that route, Jose. It gets a +1 from me. Provided we ship with one advanced theme that uses all these things.
Comment #12
m3avrck commentedDries how is the performance degraded on this? Makes things *very* nice IMO didn't see a performance hit (probably overlooked something).
Comment #13
dries commentedThe more I think about AJAX based tablesorting, the less sense it makes. It improves performance but introduces complexity and usability quircks.
Comment #14
drummNo longer applies.
Comment #15
wim leers*bump*
This would have to be rewritten in jQuery. Is there enough interest to get this in core?
Comment #16
wim leersNo interest I suppose.
Comment #17
dave reidThis would likely have much more success with the Tablesorter jQuery plugin (http://tablesorter.com/docs/) which pretty much rocks. I'd like to put it out there for Drupal 8.
Comment #18
valthebaldI'm not sure this is still relevant, keeping in mind views (including AJAX-enabled views, of course) are in core now
Comment #19
jhedstromComment #20
dawehnerI kinda agree here, it doesn't make sense anymore that much.
@Dave Reid argued that we should use client site sorting which might be fine for some sites, but especially pages like
/admin/contenttotallyrequire proper serverside sorting in order to be useful