Default sort doesn't work

Created on 27 April 2020, over 4 years ago
Updated 31 January 2024, 11 months ago

Default sort doesn't work.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇦Canada JLucySong

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇷France Chris64 France

    A real problem exists here. And the arguments of the related issue #3131305: Default Sort Order Not Working are right,

    The Default sort order does not work because the code continually resets the aaSorting to an empty array as it loops over each field, so only the last column could be default sorted.

    Should be changed the inside loop code,

        // Set default sort order.
        $datatable_options['aaSorting'] = [];
        if ($options['default'] == $field) {
          $datatable_options['aaSorting'] = [[$position, $options['order']]];
        }

    puting $datatable_options['aaSorting'] = []; out of the loop. Enough. Although necessary.

    $datatable_options['aaSorting'] is a global information to the table. If no column is chosen as default $options['default'] is set to -1 and never match $field, meaning $datatable_options['aaSorting'] need to be initialized. If a column is chosen (only one since radio button) $options['default'] is set to the corresponding field name and one match exists in the loop.

    Also possible the change,
    $datatable_options['aaSorting'] = [[$position, $options['order']]];
    ->
    $datatable_options['aaSorting'][] = [$position, $options['order']];
    In this way some thing wrong in the $datatable_options['aaSorting'] processing is more visible.

  • 🇫🇷France Chris64 France

    The patch corresponding to #4 for 2.x-dev.

  • 🇫🇷France Chris64 France

    With the right issue number.

  • Status changed to Needs work about 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Changes LGTM @Chris64. Could you please prepare this as MR?

  • 🇩🇪Germany Anybody Porta Westfalica
  • Merge request !15datatables-default-sort-3131305-5_0.patch → (Merged) created by Chris64
  • Status changed to Needs review about 1 year ago
  • 🇫🇷France Chris64 France

    MR ready.

  • Status changed to RTBC about 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    RTBC for MR!15 - thank you @Chris64. Final test by maintainer.

  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    @Chris64: is the related issue fixed by this patch too? (Extraordinay contribution by the way @Chris64 and @Anybody, I added a credit section for special thanks and listed you both on the project page.)

  • Status changed to Fixed 11 months ago
  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    Merged and queued for upcoming release.

  • 🇫🇷France Chris64 France

    @diqidoq, the related issue #3014926 is from the 7.x-1.x-dev version, and the code is a little different. But it is the same problem in the code, as noted by @Anybody. This patch does not apply to the 7.x version.

  • 🇫🇷France dqd London | N.Y.C | Paris | Hamburg | Berlin

    Ah yes, of course... Sorry I missed the different version. Then all is self explanatory. Thanks!

    Awesome contributions @Chris64. I'll think already about how to embrace your comittment to the Drupal community. +1

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024