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.

Issue fork datatables-3449376

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Volha_Si created an issue. See original summary.

volha_si’s picture

Issue summary: View changes

Volha_Si changed the visibility of the branch 3449376-wrong-default-sorting to hidden.

volha_si’s picture

Status: Active » Needs review
nigelcunningham’s picture

Status: Needs review » Reviewed & tested by the community

Reviewed and used by me. Please merge.