Skip to content

Commit

Permalink
5409cb063df85deaaf952d962333cef6e061f4d3 Fix: :visible on its own a…
Browse files Browse the repository at this point in the history
…s a column selector could incorrectly include hidden columns when used with a complex header.

https://datatables.net/forums/discussion/79089

Sync to source repo @5409cb063df85deaaf952d962333cef6e061f4d3
  • Loading branch information
dtbuild committed May 23, 2024
1 parent d980044 commit 5955366
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
2 changes: 1 addition & 1 deletion datatables.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
],
"src-repo": "http://github.com/DataTables/DataTablesSrc",
"last-tag": "2.0.7",
"last-sync": "51b19797b71eb355e827d02e3be041ed9ec999b7"
"last-sync": "5409cb063df85deaaf952d962333cef6e061f4d3"
}
29 changes: 18 additions & 11 deletions js/dataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -8264,7 +8264,7 @@
// can be an array of these items, comma separated list, or an array of comma
// separated lists

var __re_column_selector = /^([^:]+):(name|title|visIdx|visible)$/;
var __re_column_selector = /^([^:]+)?:(name|title|visIdx|visible)$/;


// r1 and r2 are redundant - but it means that the parameters match for the
Expand Down Expand Up @@ -8336,17 +8336,24 @@
switch( match[2] ) {
case 'visIdx':
case 'visible':
var idx = parseInt( match[1], 10 );
// Visible index given, convert to column index
if ( idx < 0 ) {
// Counting from the right
var visColumns = columns.map( function (col,i) {
return col.bVisible ? i : null;
} );
return [ visColumns[ visColumns.length + idx ] ];
if (match[1]) {
var idx = parseInt( match[1], 10 );
// Visible index given, convert to column index
if ( idx < 0 ) {
// Counting from the right
var visColumns = columns.map( function (col,i) {
return col.bVisible ? i : null;
} );
return [ visColumns[ visColumns.length + idx ] ];
}
// Counting from the left
return [ _fnVisibleToColumnIndex( settings, idx ) ];
}
// Counting from the left
return [ _fnVisibleToColumnIndex( settings, idx ) ];

// `:visible` on its own
return columns.map( function (col, i) {
return col.bVisible ? i : null;
} );

case 'name':
// match by name. `names` is column index complete and in order
Expand Down
2 changes: 1 addition & 1 deletion js/dataTables.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dataTables.min.mjs

Large diffs are not rendered by default.

29 changes: 18 additions & 11 deletions js/dataTables.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8211,7 +8211,7 @@ _api_register( _child_obj+'.isShown()', function () {
// can be an array of these items, comma separated list, or an array of comma
// separated lists

var __re_column_selector = /^([^:]+):(name|title|visIdx|visible)$/;
var __re_column_selector = /^([^:]+)?:(name|title|visIdx|visible)$/;


// r1 and r2 are redundant - but it means that the parameters match for the
Expand Down Expand Up @@ -8283,17 +8283,24 @@ var __column_selector = function ( settings, selector, opts )
switch( match[2] ) {
case 'visIdx':
case 'visible':
var idx = parseInt( match[1], 10 );
// Visible index given, convert to column index
if ( idx < 0 ) {
// Counting from the right
var visColumns = columns.map( function (col,i) {
return col.bVisible ? i : null;
} );
return [ visColumns[ visColumns.length + idx ] ];
if (match[1]) {
var idx = parseInt( match[1], 10 );
// Visible index given, convert to column index
if ( idx < 0 ) {
// Counting from the right
var visColumns = columns.map( function (col,i) {
return col.bVisible ? i : null;
} );
return [ visColumns[ visColumns.length + idx ] ];
}
// Counting from the left
return [ _fnVisibleToColumnIndex( settings, idx ) ];
}
// Counting from the left
return [ _fnVisibleToColumnIndex( settings, idx ) ];

// `:visible` on its own
return columns.map( function (col, i) {
return col.bVisible ? i : null;
} );

case 'name':
// match by name. `names` is column index complete and in order
Expand Down

0 comments on commit 5955366

Please sign in to comment.