datatables.net 2.0.0 → 2.0.2

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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! DataTables 2.0.0
1
+ /*! DataTables 2.0.2
2
2
  * © SpryMedia Ltd - datatables.net/license
3
3
  */
4
4
 
@@ -264,7 +264,7 @@ var DataTable = function ( selector, options )
264
264
  _fnCamelToHungarian( defaults.oLanguage, json );
265
265
  $.extend( true, oLanguage, json, oSettings.oInit.oLanguage );
266
266
 
267
- _fnCallbackFire( oSettings, null, 'i18n', [oSettings]);
267
+ _fnCallbackFire( oSettings, null, 'i18n', [oSettings], true);
268
268
  _fnInitialise( oSettings );
269
269
  },
270
270
  error: function () {
@@ -2302,7 +2302,7 @@ function _columnAutoRender(settings, colIdx) {
2302
2302
  */
2303
2303
  function _columnAutoClass(container, colIdx, className) {
2304
2304
  container.forEach(function (row) {
2305
- if (row[colIdx].unique) {
2305
+ if (row[colIdx] && row[colIdx].unique) {
2306
2306
  _addClass(row[colIdx].cell, className);
2307
2307
  }
2308
2308
  });
@@ -2376,24 +2376,32 @@ function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, headerLayout, fn )
2376
2376
  else if ( typeof target === 'string' )
2377
2377
  {
2378
2378
  for ( k=0, kLen=columns.length ; k<kLen ; k++ ) {
2379
- if (target.indexOf(':name') !== -1) {
2379
+ if (target === '_all') {
2380
+ // Apply to all columns
2381
+ fn( k, def );
2382
+ }
2383
+ else if (target.indexOf(':name') !== -1) {
2384
+ // Column selector
2380
2385
  if (columns[k].sName === target.replace(':name', '')) {
2381
2386
  fn( k, def );
2382
2387
  }
2383
2388
  }
2384
2389
  else {
2390
+ // Cell selector
2385
2391
  headerLayout.forEach(function (row) {
2386
- var cell = $(row[k].cell);
2387
-
2388
- // Legacy support. Note that it means that we don't support
2389
- // an element name selector only, since they are treated as
2390
- // class names for 1.x compat.
2391
- if (target.match(/^[a-z][\w-]*$/i)) {
2392
- target = '.' + target;
2393
- }
2394
-
2395
- if (target === '_all' || cell.is( target )) {
2396
- fn( k, def );
2392
+ if (row[k]) {
2393
+ var cell = $(row[k].cell);
2394
+
2395
+ // Legacy support. Note that it means that we don't support
2396
+ // an element name selector only, since they are treated as
2397
+ // class names for 1.x compat.
2398
+ if (target.match(/^[a-z][\w-]*$/i)) {
2399
+ target = '.' + target;
2400
+ }
2401
+
2402
+ if (cell.is( target )) {
2403
+ fn( k, def );
2404
+ }
2397
2405
  }
2398
2406
  });
2399
2407
  }
@@ -2977,7 +2985,7 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
2977
2985
  for ( i=0, iLen=oSettings.aoColumns.length ; i<iLen ; i++ )
2978
2986
  {
2979
2987
  oCol = oSettings.aoColumns[i];
2980
- create = nTrIn ? false : true;
2988
+ create = nTrIn && anTds[i] ? false : true;
2981
2989
 
2982
2990
  nTd = create ? document.createElement( oCol.sCellType ) : anTds[i];
2983
2991
 
@@ -3006,11 +3014,11 @@ function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
3006
3014
  }
3007
3015
 
3008
3016
  // Visibility - add or remove as required
3009
- if ( oCol.bVisible && ! nTrIn )
3017
+ if ( oCol.bVisible && create )
3010
3018
  {
3011
3019
  nTr.appendChild( nTd );
3012
3020
  }
3013
- else if ( ! oCol.bVisible && nTrIn )
3021
+ else if ( ! oCol.bVisible && ! create )
3014
3022
  {
3015
3023
  nTd.parentNode.removeChild( nTd );
3016
3024
  }
@@ -3094,14 +3102,23 @@ function _fnBuildHead( settings, side )
3094
3102
  }
3095
3103
 
3096
3104
  // If no cells yet and we have content for them, then create
3097
- if ( $('th, td', target).length === 0 && (side === 'header' || _pluck(settings.aoColumns, titleProp).join('')) ) {
3098
- row = $('<tr/>')
3099
- .appendTo( target );
3105
+ if (side === 'header' || _pluck(settings.aoColumns, titleProp).join('')) {
3106
+ row = $('tr', target);
3100
3107
 
3101
- for ( i=0, ien=columns.length ; i<ien ; i++ ) {
3102
- $('<th/>')
3103
- .html( columns[i][titleProp] || '' )
3104
- .appendTo( row );
3108
+ // Add a row if needed
3109
+ if (! row.length) {
3110
+ row = $('<tr/>').appendTo(target)
3111
+ }
3112
+
3113
+ // Add the number of cells needed to make up to the number of columns
3114
+ if (row.length === 1) {
3115
+ var cells = $('td, th', row);
3116
+
3117
+ for ( i=cells.length, ien=columns.length ; i<ien ; i++ ) {
3118
+ $('<th/>')
3119
+ .html( columns[i][titleProp] || '' )
3120
+ .appendTo( row );
3121
+ }
3105
3122
  }
3106
3123
  }
3107
3124
 
@@ -3198,11 +3215,15 @@ function _fnHeaderLayout( settings, source, incColumns )
3198
3215
  colspan++;
3199
3216
  }
3200
3217
 
3218
+ var titleSpan = $('span.dt-column-title', cell);
3219
+
3201
3220
  structure[row][column] = {
3202
3221
  cell: cell,
3203
3222
  colspan: colspan,
3204
3223
  rowspan: rowspan,
3205
- title: $('span.dt-column-title', cell).html()
3224
+ title: titleSpan.length
3225
+ ? titleSpan.html()
3226
+ : $(cell).html()
3206
3227
  };
3207
3228
  }
3208
3229
  }
@@ -3409,8 +3430,10 @@ function _emptyRow ( settings ) {
3409
3430
  var zero = oLang.sZeroRecords;
3410
3431
  var dataSrc = _fnDataSource( settings );
3411
3432
 
3412
- if ( settings.iDraw <= 1 && (dataSrc === 'ajax' || dataSrc === 'ssp') )
3413
- {
3433
+ if (
3434
+ (settings.iDraw < 1 && dataSrc === 'ssp') ||
3435
+ (settings.iDraw <= 1 && dataSrc === 'ajax')
3436
+ ) {
3414
3437
  zero = oLang.sLoadingRecords;
3415
3438
  }
3416
3439
  else if ( oLang.sEmptyTable && settings.fnRecordsTotal() === 0 )
@@ -3456,30 +3479,34 @@ function _layoutArray ( settings, layout, side )
3456
3479
  'full' :
3457
3480
  splitPos[1].toLowerCase();
3458
3481
  var group = groups[ splitPos[0] ];
3459
-
3460
- // Transform to an object with a contents property
3461
- if ( $.isPlainObject( val ) ) {
3462
- // Already a group from a previous pass
3463
- if (val.contents) {
3464
- group[ align ] = val;
3482
+ var groupRun = function (contents, innerVal) {
3483
+ // If it is an object, then there can be multiple features contained in it
3484
+ if ( $.isPlainObject( innerVal ) ) {
3485
+ Object.keys(innerVal).map(function (key) {
3486
+ contents.push( {
3487
+ feature: key,
3488
+ opts: innerVal[key]
3489
+ });
3490
+ });
3465
3491
  }
3466
3492
  else {
3467
- // For objects, each property becomes an entry in the contents
3468
- // array for this insert position
3469
- group[ align ] = {
3470
- contents: Object.keys(val).map(function (key) {
3471
- return {
3472
- feature: key,
3473
- opts: val[key]
3474
- };
3475
- })
3476
- };
3493
+ contents.push(innerVal);
3494
+ }
3495
+ }
3496
+
3497
+ // Transform to an object with a contents property
3498
+ if (! group[align] || ! group[align].contents) {
3499
+ group[align] = { contents: [] };
3500
+ }
3501
+
3502
+ // Allow for an array or just a single object
3503
+ if ( Array.isArray(val)) {
3504
+ for (var i=0 ; i<val.length ; i++) {
3505
+ groupRun(group[align].contents, val[i]);
3477
3506
  }
3478
3507
  }
3479
3508
  else {
3480
- group[ align ] = {
3481
- contents: val
3482
- };
3509
+ groupRun(group[ align ].contents, val);
3483
3510
  }
3484
3511
 
3485
3512
  // And make contents an array
@@ -3981,7 +4008,12 @@ function _fnBuildAjax( oSettings, data, fn )
3981
4008
  oSettings.jqXHR = ajax.call( instance, data, callback, oSettings );
3982
4009
  }
3983
4010
  else if (ajax.url === '') {
3984
- callback({});
4011
+ // No url, so don't load any data. Just apply an empty data array
4012
+ // to the object for the callback.
4013
+ var empty = {};
4014
+
4015
+ DataTable.util.set(ajax.dataSrc)(empty, []);
4016
+ callback(empty);
3985
4017
  }
3986
4018
  else {
3987
4019
  // Object to extend the base settings
@@ -4360,6 +4392,9 @@ function _fnFilterCreateSearch( search, inOpts )
4360
4392
  search = search.toString();
4361
4393
  }
4362
4394
 
4395
+ // Remove diacritics if normalize is set up to do so
4396
+ search = _normalize(search);
4397
+
4363
4398
  if (options.exact) {
4364
4399
  return new RegExp(
4365
4400
  '^'+_fnEscapeRegex(search)+'$',
@@ -4980,12 +5015,12 @@ function _fnScrollDraw ( settings )
4980
5015
  // the content of the cell so that the width applied to the header and body
4981
5016
  // both match, but we want to hide it completely.
4982
5017
  $('th, td', headerCopy).each(function () {
4983
- $(this).children().wrapAll('<div class="dt-scroll-sizing">');
5018
+ $(this.childNodes).wrapAll('<div class="dt-scroll-sizing">');
4984
5019
  });
4985
5020
 
4986
5021
  if ( footer ) {
4987
5022
  $('th, td', footerCopy).each(function () {
4988
- $(this).children().wrapAll('<div class="dt-scroll-sizing">');
5023
+ $(this.childNodes).wrapAll('<div class="dt-scroll-sizing">');
4989
5024
  });
4990
5025
  }
4991
5026
 
@@ -5340,30 +5375,41 @@ function _fnSortInit( settings ) {
5340
5375
 
5341
5376
  function _fnSortAttachListener(settings, node, selector, column, callback) {
5342
5377
  _fnBindAction( node, selector, function (e) {
5378
+ var run = false;
5343
5379
  var columns = column === undefined
5344
5380
  ? _fnColumnsFromHeader( e.target )
5345
5381
  : [column];
5346
5382
 
5347
5383
  if ( columns.length ) {
5348
- _fnProcessingDisplay( settings, true );
5384
+ for ( var i=0, ien=columns.length ; i<ien ; i++ ) {
5385
+ var ret = _fnSortAdd( settings, columns[i], i, e.shiftKey );
5349
5386
 
5350
- // Allow the processing display to show
5351
- setTimeout( function () {
5352
- for ( var i=0, ien=columns.length ; i<ien ; i++ ) {
5353
- var append = e.shiftKey || i > 0;
5354
-
5355
- _fnSortAdd( settings, columns[i], append );
5387
+ if (ret !== false) {
5388
+ run = true;
5389
+ }
5390
+
5391
+ // If the first entry is no sort, then subsequent
5392
+ // sort columns are ignored
5393
+ if (settings.aaSorting.length === 1 && settings.aaSorting[0][1] === '') {
5394
+ break;
5356
5395
  }
5396
+ }
5357
5397
 
5358
- _fnSort( settings );
5359
- _fnSortDisplay( settings );
5360
- _fnReDraw( settings, false, false );
5361
- _fnProcessingDisplay( settings, false );
5398
+ if (run) {
5399
+ _fnProcessingDisplay( settings, true );
5362
5400
 
5363
- if (callback) {
5364
- callback();
5365
- }
5366
- }, 0);
5401
+ // Allow the processing display to show
5402
+ setTimeout( function () {
5403
+ _fnSort( settings );
5404
+ _fnSortDisplay( settings );
5405
+ _fnReDraw( settings, false, false );
5406
+ _fnProcessingDisplay( settings, false );
5407
+
5408
+ if (callback) {
5409
+ callback();
5410
+ }
5411
+ }, 0);
5412
+ }
5367
5413
  }
5368
5414
  } );
5369
5415
  }
@@ -5375,9 +5421,23 @@ function _fnSortAttachListener(settings, node, selector, column, callback) {
5375
5421
  function _fnSortDisplay(settings) {
5376
5422
  var display = settings.aiDisplay;
5377
5423
  var master = settings.aiDisplayMaster;
5424
+ var masterMap = {};
5425
+ var map = {};
5426
+ var i;
5378
5427
 
5379
- display.sort(function(a, b){
5380
- return master.indexOf(a) - master.indexOf(b);
5428
+ // Rather than needing an `indexOf` on master array, we can create a map
5429
+ for (i=0 ; i<master.length ; i++) {
5430
+ masterMap[master[i]] = i;
5431
+ }
5432
+
5433
+ // And then cache what would be the indexOf fom the display
5434
+ for (i=0 ; i<display.length ; i++) {
5435
+ map[display[i]] = masterMap[display[i]];
5436
+ }
5437
+
5438
+ display.sort(function(a, b){
5439
+ // Short version of this function is simply `master.indexOf(a) - master.indexOf(b);`
5440
+ return map[a] - map[b];
5381
5441
  });
5382
5442
  }
5383
5443
 
@@ -5628,12 +5688,12 @@ function _fnSort ( oSettings, col, dir )
5628
5688
  * @param {object} settings dataTables settings object
5629
5689
  * @param {node} attachTo node to attach the handler to
5630
5690
  * @param {int} colIdx column sorting index
5631
- * @param {boolean} [append=false] Append the requested sort to the existing
5632
- * sort if true (i.e. multi-column sort)
5691
+ * @param {int} addIndex Counter
5692
+ * @param {boolean} [shift=false] Shift click add
5633
5693
  * @param {function} [callback] callback function
5634
5694
  * @memberof DataTable#oApi
5635
5695
  */
5636
- function _fnSortAdd ( settings, colIdx, append )
5696
+ function _fnSortAdd ( settings, colIdx, addIndex, shift )
5637
5697
  {
5638
5698
  var col = settings.aoColumns[ colIdx ];
5639
5699
  var sorting = settings.aaSorting;
@@ -5653,7 +5713,7 @@ function _fnSortAdd ( settings, colIdx, append )
5653
5713
  };
5654
5714
 
5655
5715
  if ( ! col.bSortable ) {
5656
- return;
5716
+ return false;
5657
5717
  }
5658
5718
 
5659
5719
  // Convert to 2D array if needed
@@ -5662,7 +5722,7 @@ function _fnSortAdd ( settings, colIdx, append )
5662
5722
  }
5663
5723
 
5664
5724
  // If appending the sort then we are multi-column sorting
5665
- if ( append && settings.oFeatures.bSortMulti ) {
5725
+ if ( (shift || addIndex) && settings.oFeatures.bSortMulti ) {
5666
5726
  // Are we already doing some kind of sort on this column?
5667
5727
  var sortIdx = _pluck(sorting, '0').indexOf(colIdx);
5668
5728
 
@@ -5682,11 +5742,18 @@ function _fnSortAdd ( settings, colIdx, append )
5682
5742
  sorting[sortIdx]._idx = nextSortIdx;
5683
5743
  }
5684
5744
  }
5685
- else {
5686
- // No sort on this column yet
5745
+ else if (shift) {
5746
+ // No sort on this column yet, being added by shift click
5747
+ // add it as itself
5687
5748
  sorting.push( [ colIdx, asSorting[0], 0 ] );
5688
5749
  sorting[sorting.length-1]._idx = 0;
5689
5750
  }
5751
+ else {
5752
+ // No sort on this column yet, being added from a colspan
5753
+ // so add with same direction as first column
5754
+ sorting.push( [ colIdx, sorting[0][1], 0 ] );
5755
+ sorting[sorting.length-1]._idx = 0;
5756
+ }
5690
5757
  }
5691
5758
  else if ( sorting.length && sorting[0][0] == colIdx ) {
5692
5759
  // Single column - already sorting on this column, modify the sort
@@ -7971,7 +8038,7 @@ var __details_events = function ( settings )
7971
8038
  for ( var i=0, ien=data.length ; i<ien ; i++ ) {
7972
8039
  row = data[i];
7973
8040
 
7974
- if ( row._details ) {
8041
+ if ( row && row._details ) {
7975
8042
  row._details.each(function () {
7976
8043
  var el = $(this).children('td');
7977
8044
 
@@ -7990,7 +8057,7 @@ var __details_events = function ( settings )
7990
8057
  }
7991
8058
 
7992
8059
  for ( var i=0, ien=data.length ; i<ien ; i++ ) {
7993
- if ( data[i]._details ) {
8060
+ if ( data[i] && data[i]._details ) {
7994
8061
  __details_remove( api, i );
7995
8062
  }
7996
8063
  }
@@ -8012,9 +8079,9 @@ _api_register( _child_mth, function ( data, klass ) {
8012
8079
 
8013
8080
  if ( data === undefined ) {
8014
8081
  // get
8015
- return ctx.length && this.length ?
8016
- ctx[0].aoData[ this[0] ]._details :
8017
- undefined;
8082
+ return ctx.length && this.length && ctx[0].aoData[ this[0] ]
8083
+ ? ctx[0].aoData[ this[0] ]._details
8084
+ : undefined;
8018
8085
  }
8019
8086
  else if ( data === true ) {
8020
8087
  // show
@@ -9337,6 +9404,8 @@ _api_register( 'destroy()', function ( remove ) {
9337
9404
  jqTable.append( tfoot );
9338
9405
  }
9339
9406
 
9407
+ settings.colgroup.remove();
9408
+
9340
9409
  settings.aaSorting = [];
9341
9410
  settings.aaSortingFixed = [];
9342
9411
  _fnSortingClasses( settings );
@@ -9436,7 +9505,7 @@ _api_register( 'i18n()', function ( token, def, plural ) {
9436
9505
  * @type string
9437
9506
  * @default Version number
9438
9507
  */
9439
- DataTable.version = "2.0.0";
9508
+ DataTable.version = "2.0.2";
9440
9509
 
9441
9510
  /**
9442
9511
  * Private data store, containing all of the settings objects that are
@@ -12181,7 +12250,7 @@ $.extend( true, DataTable.ext.renderer, {
12181
12250
  } );
12182
12251
 
12183
12252
  // Common function to remove new lines, strip HTML and diacritic control
12184
- var _filterString = function (stripHtml, diacritics) {
12253
+ var _filterString = function (stripHtml, normalize) {
12185
12254
  return function (str) {
12186
12255
  if (_empty(str) || typeof str !== 'string') {
12187
12256
  return str;
@@ -12193,8 +12262,8 @@ var _filterString = function (stripHtml, diacritics) {
12193
12262
  str = _stripHtml(str);
12194
12263
  }
12195
12264
 
12196
- if (diacritics) {
12197
- str = _normalize(str, true);
12265
+ if (normalize) {
12266
+ str = _normalize(str, false);
12198
12267
  }
12199
12268
 
12200
12269
  return str;
@@ -12572,7 +12641,7 @@ DataTable.type = function (name, prop, val) {
12572
12641
  };
12573
12642
 
12574
12643
  // prop is optional
12575
- if (! val) {
12644
+ if (val === undefined) {
12576
12645
  val = prop;
12577
12646
  prop = null;
12578
12647
  }
@@ -13231,7 +13300,7 @@ function _pagingDraw(settings, host, opts) {
13231
13300
  if (
13232
13301
  buttonEls.length && // any buttons
13233
13302
  opts.numbers > 1 && // prevent infinite
13234
- $(host).outerHeight() >= ($(buttonEls[0]).outerHeight() * 2) - 10
13303
+ $(host).height() >= ($(buttonEls[0]).outerHeight() * 2) - 10
13235
13304
  ) {
13236
13305
  _pagingDraw(settings, host, $.extend({}, opts, { numbers: opts.numbers - 2 }));
13237
13306
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "js/dataTables.js",
5
5
  "module": "js/dataTables.mjs",
6
6
  "types": "./types/types.d.ts",
7
- "version": "2.0.0",
7
+ "version": "2.0.2",
8
8
  "files": [
9
9
  "js/**/*.js",
10
10
  "js/**/*.mjs",