1
0
mirror of https://github.com/DataTables/DataTables.git synced 2025-01-30 23:52:11 +01:00

API: Column selector - add support for visible indexes counting from the right

- The ability to use negative numbers as a column selector for the
  column data index was added recently, but that didn't include the
  ability to work with negative numbers with the :visible pesudo
  selector. This commit adds that ability so you can do:
  `table.column("-1:visible")` to always get the right most visible
  column
This commit is contained in:
Allan Jardine 2013-11-19 13:55:08 +00:00
parent 32e27fcc2f
commit 7a32f2db93
2 changed files with 14 additions and 8 deletions

View File

@ -1 +1 @@
cc7a50b02dc22913382fd07c4524541bb8111d77
7e07090066442c9e1b4bcbaf9c2b566f7af974fe

View File

@ -7642,12 +7642,9 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Columns
*
* {integer} - column index >= 0 (count from left)
* "{integer}" - column index >= 0 (count from left)
* {integer} - column index < 0 (count from right)
* "{integer}" - column index < 0 (count from right)
* "{integer}:visIdx" - visible column index (i.e. translate to column index)
* "{integer}:visible" - alias for {integer}:visIdx
* {integer} - column index (>=0 count from left, <0 count from right)
* "{integer}:visIdx" - visible column index (i.e. translate to column index) (>=0 count from left, <0 count from right)
* "{integer}:visible" - alias for {integer}:visIdx (>=0 count from left, <0 count from right)
* "{string}:name" - column name
* "{string}" - jQuery selector on column header nodes
*
@ -7686,8 +7683,17 @@
switch( match[2] ) {
case 'visIdx':
case 'visible':
var idx = parseInt( match[1], 10 );
// Visible index given, convert to column index
return [ _fnVisibleToColumnIndex( settings, parseInt( match[1], 10 ) ) ];
if ( idx < 0 ) {
// Counting from the right
var visColumns = $.map( columns, function (col,i) {
return col.bVisible ? i : null;
} );
return [ visColumns[ visColumns.length + idx ] ];
}
// Counting from the left
return [ _fnVisibleToColumnIndex( settings, idx ) ];
case 'name':
// match by name. `names` is column index complete and in order