Wrong default sorting if a view has fields excluded from display

Created on 23 May 2024, 6 months ago

Problem/Motivation

If a view has excluded from display field - the default sorting uses the wrong field to sort.

Steps to reproduce

1. Create a view with field 1, field 2 and field3.
2. Exclude field1 from display (do not hide it via Datatables, but exclude via Views).
3. Set default sorting by the field 2.
AR: The view is sorted by default by the field 3.
EXR: The view is sorted by default by the field 2, as set in settings.

Explanation:
This code in datatables.module takes a position of the field among all the fields (exluded and non-excluded):

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

    $position++;*/

But on the js side the field is selected by it's position among non-excluded fields - and it can be totally the other position if there were excluded fields before.

Proposed resolution

Calculate the position only among non-excluded fields.

🐛 Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024