Needs work
Project:
TableField
Version:
3.0.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
20 Mar 2012 at 22:08 UTC
Updated:
24 Mar 2025 at 13:29 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
Mołot commentedhttp://tablesorter.com/docs/ - this jQuery plugin might help, if all you want is to sort on display.
Comment #2
lolandese commentedComment #3
dedicated_hobby_coder commentedhttps://www.drupal.org/project/tablesorter
Comment #4
lolandese commentedExcellent suggestion and IMHO the way to go.
Needed is a display option (checkbox) 'Sortable' that adds the class 'tablesorter' to the table, probably through $variables['attributes']. Note that we have a patch currently under review that swaps the core theme_table() with the custom theme_tablefield(). That was needed to make vertical headers possible (first column instead of first row). See #2058325: [D7]: Allow to have the first column as header instead of first row.
NOTE: The sort functionality should be disabled in case we only have a vertical header.
Implementation is however similar for both theme functions so a patch can be provided anyhow. Feel free to do so.
We noticed Tablesorter offers some styling. Best is to stick with System's Default and let the implemented theme take care of the styling. To look into how various core themes deal with that. In theme.inc we have the function theme_tablesort_indicator($variables) that might come handy.
Comment #5
lolandese commentedCSS start for the sort arrows to indicate the column is sortable:
.. or something like http://stackoverflow.com/a/22222257/523688.
Alternatively using a symbol plus text. See http://ux.stackexchange.com/a/80233.
Comment #6
lolandese commentedAlso make sure to apply the patch in #2716277: Multiple tables on same page not working for https://www.drupal.org/project/tablesorter.
Comment #8
lolandese commentedComment #9
lolandese commentedWe probably could improve it by avoiding inline styling and use the tablesorter class at least for the mouse pointer on hover.
Not sure if we can do the same for the title (tooltip).
Comment #10
lolandese commented#9 plus disable the sort option in the settings if we only have a vertical header.
Comment #12
lolandese commentedComment #14
lolandese commentedComment #15
lolandese commentedComment #16
lolandese commentedPort 7.x-3.x features to a new 8.x-3.x version (to be created).
Comment #17
douggreen commentedAttached patch for D8/9. This is a re-implementation, rather than a port. A couple of notes:
* A moduleExists() check before adding a class is unnecessary IMO so I didn't add it.
* The sortable column defaults to 1 if tablesorter is enabled, otherwise it's 0.
* No additional styling is done, tablesorter seems to style just fine to me.
Comment #18
lolandese commentedChanging status to trigger the test on the supplied patch.
Comment #19
jayhuskinshook_update_8002 is used in another patch, so this patch updates the number to 8010 to remove the conflict.
Comment #20
douggreen commentedWe shouldn't renumber this way, update's should be sequential, if there's a conflict between two patches being applied, usually you copy the patch locally and apply your local patch. I'm removing #19 and restoring #17 as the primary patch for this reason. I'm leaving #10 because that's an alternative solution.
Comment #21
bala.addweb commentedsort-table-on-header-click.patch
Comment #22
erutan commentedThe patches in this issue queue no longer work in Drupal 10.3.10.
#21 applied cleanly, but there were no options for sortable tables and no sortable tables automatically.
#19 popped up the following error multiple times when loading the entity with the field I want to sort in the admin edit interface:
Furthermore if I go to edit a tablefield @ /admin/structure/storage_types/foo/edit/fields/ I get a whitescreen with the following:
Comment #23
erutan commented#19 is loading the JS lib, tr/td have a different background color and there are grey triangles to use as sort toggles, but it is not interactive.
Comment #24
tim-dielsPatch from #17 and patch from #21 are quiet different.
What is the expected approach here to have table sorting added? I see the module uses the Tablesorter module for the 7.x version and that was the same as with patch from #17 but the person in #21 decided on itself that they wanted to go a different approach without explaining why.
I'm more of a fan of using the Tablesorter module as this is also what the maintainer proposed on using. So can we have a concensus on using this approach?
Comment #26
tim-dielsAdded patch from #17 to the latest codebase so going to hide all other patches.
I think a nice follow up would be a setting to allow to specify what columns should be sortable as the library supports this. But that could be a separate issue so this can go in as is and the change is not to big.
Comment #27
tim-dielsComment #28
tim-dielsThe code works for me, only no visual for sorting. Is this something that is needed for the tablesorter module itself or it could be added here as done in the 7.x branch. The tablesorter said is is something the theme should fix. So maybe just some documentation and just the cursor set to pointer?
Setting to needs work for the css.
Comment #29
tim-dielsWe can also suggest installing the tablesorter in a composer file...
Comment #30
erutan commentedWould it be more appropriate if the functionality of this patch was a submodule included with TableField?
If someone installs TableField Sort (or some other name) then we can have tablesorter installed as a dependency. This wouldn't impact people that don't want the functionality while making it simpler for those that do.
There isn't a stable build of tablesorter for D8+, but the 2.0 branch is up to RC2 and around a third of the people using the module are running that branch.
Comment #31
tim-diels@erutan I do like your suggestion. But can't put time in this now to completely refactor it to be a submodule. If a maintainer could assist in deciding what would be the best approach, then we can see what we need to do to get this finished.
I understand that there is no proper release for tablesorter. I'll try to get some time to get a proper release there. I would suggest not yet adding this to a release until there is a proper release of tablesorter.
The CSS I did not add as I think this is not necessary as a theme could handle this? Any opinions on that?
Setting this to needs review as in my eyes it seems complete now.
Comment #32
erutan commentedAny thoughts on this from the more senior maintainers? I think it's be great functionality to get in.
I take a look at the CSS side of things. :)
Comment #33
liam morlandPlease rebase on 3.0.x.
Comment #39
carlos romero commentedReroll patch for 2.5 version, mr done
Comment #40
carlos romero commentedComment #41
liam morlandI don't think there is going to be any more development of 8.x-2.x. Merge request 56 is for 3.0.x. This version needs tests to all pass.