datatables.net 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/js/dataTables.js CHANGED
@@ -1,11 +1,11 @@
1
- /*! DataTables 2.0.0
1
+ /*! DataTables 2.0.1
2
2
  * © SpryMedia Ltd - datatables.net/license
3
3
  */
4
4
 
5
5
  /**
6
6
  * @summary DataTables
7
7
  * @description Paginate, search and order HTML tables
8
- * @version 2.0.0
8
+ * @version 2.0.1
9
9
  * @author SpryMedia Ltd
10
10
  * @contact www.datatables.net
11
11
  * @copyright SpryMedia Ltd.
@@ -2429,12 +2429,18 @@
2429
2429
  else if ( typeof target === 'string' )
2430
2430
  {
2431
2431
  for ( k=0, kLen=columns.length ; k<kLen ; k++ ) {
2432
- if (target.indexOf(':name') !== -1) {
2432
+ if (target === '_all') {
2433
+ // Apply to all columns
2434
+ fn( k, def );
2435
+ }
2436
+ else if (target.indexOf(':name') !== -1) {
2437
+ // Column selector
2433
2438
  if (columns[k].sName === target.replace(':name', '')) {
2434
2439
  fn( k, def );
2435
2440
  }
2436
2441
  }
2437
2442
  else {
2443
+ // Cell selector
2438
2444
  headerLayout.forEach(function (row) {
2439
2445
  var cell = $(row[k].cell);
2440
2446
 
@@ -2445,7 +2451,7 @@
2445
2451
  target = '.' + target;
2446
2452
  }
2447
2453
 
2448
- if (target === '_all' || cell.is( target )) {
2454
+ if (cell.is( target )) {
2449
2455
  fn( k, def );
2450
2456
  }
2451
2457
  });
@@ -3030,7 +3036,7 @@
3030
3036
  for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
3031
3037
  {
3032
3038
  oCol = oSettings.aoColumns[i];
3033
- create = nTrIn ? false : true;
3039
+ create = nTrIn && anTds[i] ? false : true;
3034
3040
 
3035
3041
  nTd = create ? document.createElement( oCol.sCellType ) : anTds[i];
3036
3042
 
@@ -3059,11 +3065,11 @@
3059
3065
  }
3060
3066
 
3061
3067
  // Visibility - add or remove as required
3062
- if ( oCol.bVisible && ! nTrIn )
3068
+ if ( oCol.bVisible && create )
3063
3069
  {
3064
3070
  nTr.appendChild( nTd );
3065
3071
  }
3066
- else if ( ! oCol.bVisible && nTrIn )
3072
+ else if ( ! oCol.bVisible && ! create )
3067
3073
  {
3068
3074
  nTd.parentNode.removeChild( nTd );
3069
3075
  }
@@ -3147,14 +3153,23 @@
3147
3153
  }
3148
3154
 
3149
3155
  // If no cells yet and we have content for them, then create
3150
- if ( $('th, td', target).length === 0 && (side === 'header' || _pluck(settings.aoColumns, titleProp).join('')) ) {
3151
- row = $('<tr/>')
3152
- .appendTo( target );
3156
+ if (side === 'header' || _pluck(settings.aoColumns, titleProp).join('')) {
3157
+ row = $('tr', target);
3158
+
3159
+ // Add a row if needed
3160
+ if (! row.length) {
3161
+ row = $('<tr/>').appendTo(target)
3162
+ }
3153
3163
 
3154
- for ( i=0, ien=columns.length ; i<ien ; i++ ) {
3155
- $('<th/>')
3156
- .html( columns[i][titleProp] || '' )
3157
- .appendTo( row );
3164
+ // Add the number of cells needed to make up to the number of columns
3165
+ if (row.length === 1) {
3166
+ var cells = $('td, th', row);
3167
+
3168
+ for ( i=cells.length, ien=columns.length ; i<ien ; i++ ) {
3169
+ $('<th/>')
3170
+ .html( columns[i][titleProp] || '' )
3171
+ .appendTo( row );
3172
+ }
3158
3173
  }
3159
3174
  }
3160
3175
 
@@ -3462,8 +3477,10 @@
3462
3477
  var zero = oLang.sZeroRecords;
3463
3478
  var dataSrc = _fnDataSource( settings );
3464
3479
 
3465
- if ( settings.iDraw <= 1 && (dataSrc === 'ajax' || dataSrc === 'ssp') )
3466
- {
3480
+ if (
3481
+ (settings.iDraw < 1 && dataSrc === 'ssp') ||
3482
+ (settings.iDraw <= 1 && dataSrc === 'ajax')
3483
+ ) {
3467
3484
  zero = oLang.sLoadingRecords;
3468
3485
  }
3469
3486
  else if ( oLang.sEmptyTable && settings.fnRecordsTotal() === 0 )
@@ -3509,30 +3526,34 @@
3509
3526
  'full' :
3510
3527
  splitPos[1].toLowerCase();
3511
3528
  var group = groups[ splitPos[0] ];
3512
-
3513
- // Transform to an object with a contents property
3514
- if ( $.isPlainObject( val ) ) {
3515
- // Already a group from a previous pass
3516
- if (val.contents) {
3517
- group[ align ] = val;
3529
+ var groupRun = function (contents, innerVal) {
3530
+ // If it is an object, then there can be multiple features contained in it
3531
+ if ( $.isPlainObject( innerVal ) ) {
3532
+ Object.keys(innerVal).map(function (key) {
3533
+ contents.push( {
3534
+ feature: key,
3535
+ opts: innerVal[key]
3536
+ });
3537
+ });
3518
3538
  }
3519
3539
  else {
3520
- // For objects, each property becomes an entry in the contents
3521
- // array for this insert position
3522
- group[ align ] = {
3523
- contents: Object.keys(val).map(function (key) {
3524
- return {
3525
- feature: key,
3526
- opts: val[key]
3527
- };
3528
- })
3529
- };
3540
+ contents.push(innerVal);
3541
+ }
3542
+ }
3543
+
3544
+ // Transform to an object with a contents property
3545
+ if (! group[align] || ! group[align].contents) {
3546
+ group[align] = { contents: [] };
3547
+ }
3548
+
3549
+ // Allow for an array or just a single object
3550
+ if ( Array.isArray(val)) {
3551
+ for (var i=0 ; i<val.length ; i++) {
3552
+ groupRun(group[align].contents, val[i]);
3530
3553
  }
3531
3554
  }
3532
3555
  else {
3533
- group[ align ] = {
3534
- contents: val
3535
- };
3556
+ groupRun(group[ align ].contents, val);
3536
3557
  }
3537
3558
 
3538
3559
  // And make contents an array
@@ -4413,6 +4434,9 @@
4413
4434
  search = search.toString();
4414
4435
  }
4415
4436
 
4437
+ // Remove diacritics if normalize is set up to do so
4438
+ search = _normalize(search);
4439
+
4416
4440
  if (options.exact) {
4417
4441
  return new RegExp(
4418
4442
  '^'+_fnEscapeRegex(search)+'$',
@@ -5403,9 +5427,13 @@
5403
5427
  // Allow the processing display to show
5404
5428
  setTimeout( function () {
5405
5429
  for ( var i=0, ien=columns.length ; i<ien ; i++ ) {
5406
- var append = e.shiftKey || i > 0;
5407
-
5408
- _fnSortAdd( settings, columns[i], append );
5430
+ _fnSortAdd( settings, columns[i], i, e.shiftKey );
5431
+
5432
+ // If the first entry is no sort, then subsequent
5433
+ // sort columns are ignored
5434
+ if (settings.aaSorting.length === 1 && settings.aaSorting[0][1] === '') {
5435
+ break;
5436
+ }
5409
5437
  }
5410
5438
 
5411
5439
  _fnSort( settings );
@@ -5428,9 +5456,23 @@
5428
5456
  function _fnSortDisplay(settings) {
5429
5457
  var display = settings.aiDisplay;
5430
5458
  var master = settings.aiDisplayMaster;
5459
+ var masterMap = {};
5460
+ var map = {};
5461
+ var i;
5431
5462
 
5432
- display.sort(function(a, b){
5433
- return master.indexOf(a) - master.indexOf(b);
5463
+ // Rather than needing an `indexOf` on master array, we can create a map
5464
+ for (i=0 ; i<master.length ; i++) {
5465
+ masterMap[master[i]] = i;
5466
+ }
5467
+
5468
+ // And then cache what would be the indexOf fom the display
5469
+ for (i=0 ; i<display.length ; i++) {
5470
+ map[display[i]] = masterMap[display[i]];
5471
+ }
5472
+
5473
+ display.sort(function(a, b){
5474
+ // Short version of this function is simply `master.indexOf(a) - master.indexOf(b);`
5475
+ return map[a] - map[b];
5434
5476
  });
5435
5477
  }
5436
5478
 
@@ -5681,12 +5723,12 @@
5681
5723
  * @param {object} settings dataTables settings object
5682
5724
  * @param {node} attachTo node to attach the handler to
5683
5725
  * @param {int} colIdx column sorting index
5684
- * @param {boolean} [append=false] Append the requested sort to the existing
5685
- * sort if true (i.e. multi-column sort)
5726
+ * @param {int} addIndex Counter
5727
+ * @param {boolean} [shift=false] Shift click add
5686
5728
  * @param {function} [callback] callback function
5687
5729
  * @memberof DataTable#oApi
5688
5730
  */
5689
- function _fnSortAdd ( settings, colIdx, append )
5731
+ function _fnSortAdd ( settings, colIdx, addIndex, shift )
5690
5732
  {
5691
5733
  var col = settings.aoColumns[ colIdx ];
5692
5734
  var sorting = settings.aaSorting;
@@ -5715,7 +5757,7 @@
5715
5757
  }
5716
5758
 
5717
5759
  // If appending the sort then we are multi-column sorting
5718
- if ( append && settings.oFeatures.bSortMulti ) {
5760
+ if ( (shift || addIndex) && settings.oFeatures.bSortMulti ) {
5719
5761
  // Are we already doing some kind of sort on this column?
5720
5762
  var sortIdx = _pluck(sorting, '0').indexOf(colIdx);
5721
5763
 
@@ -5735,11 +5777,18 @@
5735
5777
  sorting[sortIdx]._idx = nextSortIdx;
5736
5778
  }
5737
5779
  }
5738
- else {
5739
- // No sort on this column yet
5780
+ else if (shift) {
5781
+ // No sort on this column yet, being added by shift click
5782
+ // add it as itself
5740
5783
  sorting.push( [ colIdx, asSorting[0], 0 ] );
5741
5784
  sorting[sorting.length-1]._idx = 0;
5742
5785
  }
5786
+ else {
5787
+ // No sort on this column yet, being added from a colspan
5788
+ // so add with same direction as first column
5789
+ sorting.push( [ colIdx, sorting[0][1], 0 ] );
5790
+ sorting[sorting.length-1]._idx = 0;
5791
+ }
5743
5792
  }
5744
5793
  else if ( sorting.length && sorting[0][0] == colIdx ) {
5745
5794
  // Single column - already sorting on this column, modify the sort
@@ -9390,6 +9439,8 @@
9390
9439
  jqTable.append( tfoot );
9391
9440
  }
9392
9441
 
9442
+ settings.colgroup.remove();
9443
+
9393
9444
  settings.aaSorting = [];
9394
9445
  settings.aaSortingFixed = [];
9395
9446
  _fnSortingClasses( settings );
@@ -9489,7 +9540,7 @@
9489
9540
  * @type string
9490
9541
  * @default Version number
9491
9542
  */
9492
- DataTable.version = "2.0.0";
9543
+ DataTable.version = "2.0.1";
9493
9544
 
9494
9545
  /**
9495
9546
  * Private data store, containing all of the settings objects that are
@@ -12234,7 +12285,7 @@
12234
12285
  } );
12235
12286
 
12236
12287
  // Common function to remove new lines, strip HTML and diacritic control
12237
- var _filterString = function (stripHtml, diacritics) {
12288
+ var _filterString = function (stripHtml, normalize) {
12238
12289
  return function (str) {
12239
12290
  if (_empty(str) || typeof str !== 'string') {
12240
12291
  return str;
@@ -12246,8 +12297,8 @@
12246
12297
  str = _stripHtml(str);
12247
12298
  }
12248
12299
 
12249
- if (diacritics) {
12250
- str = _normalize(str, true);
12300
+ if (normalize) {
12301
+ str = _normalize(str, false);
12251
12302
  }
12252
12303
 
12253
12304
  return str;