I think tablesort should work fine here and it almost seems like it does, but not quite. Trying to sort alphabetically here admin/people?sort=asc&order=Username I get:

jajosene	active 2 days 3 hours	1 day 9 hours ago	edit
jacophenoro	active 4 days 17 hours	1 day 9 hours ago	edit
engelund	active  1 day 6 hours	1 day 2 hours ago	edit
frunab	active	5 days 3 hours	1 day 9 hours ago	edit
gabastacle	active	6 days 10 hours	1 day 9 hours ago	edit
guwuchun	active	6 days 5 hours	1 day 9 hours ago	edit
bawracligip ...

Ordering by time admin/people?sort=asc&order=Member for i get:

stihunistu	active	2 days 23 hours	1 day 9 hours ago	edit
nethemek	active	3 days 4 hours	1 day 9 hours ago	edit
lushebi	active	2 days 22 hours	1 day 9 hours ago	edit
loswat	active	2 days 21 hours	1 day 9 hours ago	edit
swatrathi	active	2 days 20 hours	1 day 9 hours ago	edit
kaloclubuj	active		3 days 8 hours	1 day 9 hours ago	edit
wrebrobu	...

I'm not sure where this is going wrong as it does at least change between asc & desc but doesn't seem to be accurate.

CommentFileSizeAuthor
#1 847852.patch728 bytesrayasa

Comments

rayasa’s picture

Component: user system » forms system
Status: Active » Needs review
StatusFileSize
new728 bytes

Surprised to see no response for so long for such an annoying bug.

The sort functionality is broken for all tableselects such as content table, comment table, user table etc.

The problem lies in the following function

function form_process_tableselect($element) {

  .
  .
  .
    // Sort the options by their #weight if they have a #weight.
    uasort($element['#options'], 'element_sort');
  .
  .
  .
}

Here, although the comment says that the options will be sorted if they have a #weight property , but no check has been placed. So, the uasort result for unweighted options is undefined as the function element_sort compares options based on property '#weight'.
Also, for the user, node or comment table the sort results are directly obtained from the DB, and need not be re-sorted here.

The patch attached puts a check based on the assumption that all options are either weighted or all unweighted. The patch can be bettered on review.

heine’s picture

Status: Needs review » Closed (duplicate)