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
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
Comment #2
volha_si commentedComment #5
volha_si commentedComment #6
nigelcunningham commentedReviewed and used by me. Please merge.