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.

CommentFileSizeAuthor
#1 jstablesort_0.patch13.25 KBSteven
jstablesort.patch12.93 KBSteven

Comments

Steven’s picture

StatusFileSize
new13.25 KB

Missed a table in statistics.module ;).

Thox’s picture

I 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.

Steven’s picture

The 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.

m3avrck’s picture

Tried 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 :)

m3avrck’s picture

Just 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 :)

m3avrck’s picture

For 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.

Bèr Kessels’s picture

I 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.

dries’s picture

I 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.

Bèr Kessels’s picture

The 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/

jose reyero’s picture

Couldn't we just provide this as a library to be used by themes, and then leave the default theme functions free of this stuff?

Bèr Kessels’s picture

I really like that route, Jose. It gets a +1 from me. Provided we ship with one advanced theme that uses all these things.

m3avrck’s picture

Dries how is the performance degraded on this? Makes things *very* nice IMO didn't see a performance hit (probably overlooked something).

dries’s picture

The more I think about AJAX based tablesorting, the less sense it makes. It improves performance but introduces complexity and usability quircks.

drumm’s picture

Status: Needs review » Needs work

No longer applies.

wim leers’s picture

Version: x.y.z » 7.x-dev

*bump*

This would have to be rewritten in jQuery. Is there enough interest to get this in core?

wim leers’s picture

Status: Needs work » Closed (won't fix)

No interest I suppose.

dave reid’s picture

Version: 7.x-dev » 8.x-dev
Assigned: Steven » Unassigned
Status: Closed (won't fix) » Needs work

This 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.

valthebald’s picture

Issue summary: View changes
Issue tags: +needs relevance check

I'm not sure this is still relevant, keeping in mind views (including AJAX-enabled views, of course) are in core now

jhedstrom’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Needs work » Postponed (maintainer needs more info)
dawehner’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

I'm not sure this is still relevant, keeping in mind views (including AJAX-enabled views, of course) are in core now

I 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/content totally
require proper serverside sorting in order to be useful