Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When You have multiple tables displayed on one page they do not sort independently of each other. I know that in the past this was said to be a result of Drupal's tablesort functionality. I don't believe this is the case anymore and so I have written a patch for 7.x-3 and 6.x-3 that fixes this issue by using arrays in the query string to uniquely identify the view and display that are being sorted.
Comment | File | Size | Author |
---|---|---|---|
#12 | views_table_mutlisort.patch | 4.62 KB | compcom |
#6 | multi-sort-table-1160840-6.patch | 4.58 KB | arcaneadam |
views-multiple-tables-6.x.patch | 3.88 KB | arcaneadam | |
views-multiple-table-sort-7.x.patch | 3.25 KB | arcaneadam | |
Comments
Comment #1
arcaneadam CreditAttribution: arcaneadam commentedComment #2
arcaneadam CreditAttribution: arcaneadam commentedChanging the title to better reflect the issue and show that I've actually patched it to make it work rather then just complained and whined about how it doesn't work.
Comment #3
dawehnerOne principal problem of making multiple table sorts availible is that the url's will be much longer. People will complain about it :)
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedBecause of #3, this has to be optional at best, I think.
Comment #5
arcaneadam CreditAttribution: arcaneadam commentedI'll work on making it an option in the table style plugin.
Comment #6
arcaneadam CreditAttribution: arcaneadam commentedOk. I reworked how this works and have tested it on a page with two tables.
Basically I copied the pager plugins method of providing a pager ID in the settings form. So this patch provides a new field on the settings form "Table Sort ID".It is then up to the user to set this value if they are having problems with the table sort. It does however still require adding some characters to the URL. It's not much though for a page with only one table.
Old query string for sort No matter how many tables:
order=title&sort=asc
Total chars: 20
PROS: small URL footprint
CONS: No ability to sort multiple tables
New query string w/o & w/ multi-table sort:
Single Table
sort[0][order]=title&sort[0][sort]=asc
Total Chars: 38
Multi-Table
sort[1][order]=title&sort[1][sort]=asc&sort[0][order]=title&sort[0][sort]=asc
Total Chars: 77
PROS: Can sort multiple tables on a single page
CONS: If only sorting one table it adds an additional 18 characters.
I think overall thats a small price to pay for improved functionality.
The other option if this still isn't good enough is to completely make the additional $_GET[sort][x] array only be used if they supply a multisort_id. The initial sort key would need to be renamed though to avoid possible collision.
Comment #7
arcaneadam CreditAttribution: arcaneadam commentedComment #8
arcaneadam CreditAttribution: arcaneadam commentedAnother thought too if 38 is too big of. Q string is to use shorter keys for sort and order so,
sort[0][order]=title&sort[0][sort]=asc
Becomes,
sort[0][ord]=title&sort[0][st]=asc
Or something similar/shorter, but I'd prefer to stick with the descriptive keys.
Comment #9
dawehnerIt's pretty sure that this is not the right default value :)
The problem here is that it's not optional, you can't have the old style of the urls, but making it optional would sadly uglify the code quite a bit.
Comment #10
dsrikanth CreditAttribution: dsrikanth commentedDid someone manage a solution for this?
Comment #11
compcom CreditAttribution: compcom commentedFirst of all: Nice approach! Saved me quite some time, after I ran into the same issue.
To get this working with current views module:
the patch needed some adjustments...
#9 is right... the line needs to be
and then...
needs to become
updated patch file is provided...
Comment #12
compcom CreditAttribution: compcom commentedand now the - at least for me - working patch...
the sort parameter needed to be renamed to something else, to get around errors in CORE/includes/tablesort.inc (7.38).