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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arcaneadam’s picture

Status: Active » Needs review
arcaneadam’s picture

Title: Multiple Table Displays Won't sort independently » Implementing Table sort for multiple tables on single page [PATCH]

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

dawehner’s picture

One principal problem of making multiple table sorts availible is that the url's will be much longer. People will complain about it :)

merlinofchaos’s picture

Status: Needs review » Needs work

Because of #3, this has to be optional at best, I think.

arcaneadam’s picture

I'll work on making it an option in the table style plugin.

arcaneadam’s picture

Status: Needs review » Needs work
FileSize
4.58 KB

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

arcaneadam’s picture

Status: Needs work » Needs review
arcaneadam’s picture

Status: Needs work » Needs review

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

dawehner’s picture

Status: Needs review » Needs work
+++ b/plugins/views_plugin_style_table.incundefined
@@ -171,6 +174,12 @@ class views_plugin_style_table extends views_plugin_style {
+      '#default_value' => $this->options['summary'],

It'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.

dsrikanth’s picture

Did someone manage a solution for this?

compcom’s picture

Issue summary: View changes
FileSize
4.63 KB

First of all: Nice approach! Saved me quite some time, after I ran into the same issue.

To get this working with current views module:

; Information added by Drupal.org packaging script on 2015-04-29
version = "7.x-3.11"
core = "7.x"
project = "views"
datestamp = "1430321048"

the patch needed some adjustments...

#9 is right... the line needs to be

+      '#default_value' => $this->options['multisort_id'],

and then...

+  $current_key = empty($view->options['multisort_id']) ? 0 : $view->options['multisort_id'];

needs to become

+  $current_key = empty($options['multisort_id']) ? 0 : $options['multisort_id'];

updated patch file is provided...

compcom’s picture

FileSize
4.62 KB

and 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).