datatables.net 2.2.0 → 2.2.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.2.0
1
+ /*! DataTables 2.2.2
2
2
  * © SpryMedia Ltd - datatables.net/license
3
3
  */
4
4
 
@@ -5315,6 +5315,14 @@ function _fnCalculateColumnWidths ( settings )
5315
5315
  i, column, columnIdx;
5316
5316
 
5317
5317
  var styleWidth = table.style.width;
5318
+ var containerWidth = _fnWrapperWidth(settings);
5319
+
5320
+ // Don't re-run for the same width as the last time
5321
+ if (containerWidth === settings.containerWidth) {
5322
+ return false;
5323
+ }
5324
+
5325
+ settings.containerWidth = containerWidth;
5318
5326
 
5319
5327
  // If there is no width applied as a CSS style or as an attribute, we assume that
5320
5328
  // the width is intended to be 100%, which is usually is in CSS, but it is very
@@ -5442,15 +5450,15 @@ function _fnCalculateColumnWidths ( settings )
5442
5450
 
5443
5451
  // If there is no width attribute or style, then allow the table to
5444
5452
  // collapse
5445
- if ( tmpTable.width() < tableContainer.clientWidth && tableWidthAttr ) {
5446
- tmpTable.width( tableContainer.clientWidth );
5453
+ if ( tmpTable.outerWidth() < tableContainer.clientWidth && tableWidthAttr ) {
5454
+ tmpTable.outerWidth( tableContainer.clientWidth );
5447
5455
  }
5448
5456
  }
5449
5457
  else if ( scrollY ) {
5450
- tmpTable.width( tableContainer.clientWidth );
5458
+ tmpTable.outerWidth( tableContainer.clientWidth );
5451
5459
  }
5452
5460
  else if ( tableWidthAttr ) {
5453
- tmpTable.width( tableWidthAttr );
5461
+ tmpTable.outerWidth( tableWidthAttr );
5454
5462
  }
5455
5463
 
5456
5464
  // Get the width of each column in the constructed table
@@ -5483,47 +5491,43 @@ function _fnCalculateColumnWidths ( settings )
5483
5491
  }
5484
5492
 
5485
5493
  if ( (tableWidthAttr || scrollX) && ! settings._reszEvt ) {
5486
- var wrapperWidth = function () {
5487
- return $(settings.nTableWrapper).is(':visible')
5488
- ? $(settings.nTableWrapper).width()
5489
- : 0;
5490
- }
5491
-
5492
- settings.containerWidth = wrapperWidth();
5493
-
5494
5494
  var resize = DataTable.util.throttle( function () {
5495
- var newWidth = wrapperWidth();
5495
+ var newWidth = _fnWrapperWidth(settings);
5496
5496
 
5497
- // Don't do it if destroying, is the same size as last time, or the container
5498
- // width is 0
5499
- if (
5500
- ! settings.bDestroying &&
5501
- settings.containerWidth !== newWidth &&
5502
- newWidth !== 0
5503
- ) {
5504
- // Do a resize
5497
+ // Don't do it if destroying or the container width is 0
5498
+ if (! settings.bDestroying && newWidth !== 0) {
5505
5499
  _fnAdjustColumnSizing( settings );
5506
- settings.containerWidth = newWidth;
5507
5500
  }
5508
5501
  } );
5509
5502
 
5510
5503
  // For browsers that support it (~2020 onwards for wide support) we can watch for the
5511
5504
  // container changing width.
5512
5505
  if (window.ResizeObserver) {
5513
- settings.resizeObserver = new ResizeObserver(function (e) {
5514
- var box = e[0].contentBoxSize;
5515
- var size = Array.isArray(box)
5516
- ? box[0].inlineSize // Spec
5517
- : box.inlineSize; // Old Firefox
5506
+ // This is a tricky beast - if the element is visible when `.observe()` is called,
5507
+ // then the callback is immediately run. Which we don't want. If the element isn't
5508
+ // visible, then it isn't run, but we want it to run when it is then made visible.
5509
+ // This flag allows the above to be satisfied.
5510
+ var first = $(settings.nTableWrapper).is(':visible');
5511
+
5512
+ // Use an empty div to attach the observer so it isn't impacted by height changes
5513
+ var resizer = $('<div>')
5514
+ .css({
5515
+ width: '100%',
5516
+ height: 0
5517
+ })
5518
+ .addClass('dt-autosize')
5519
+ .appendTo(settings.nTableWrapper);
5518
5520
 
5519
- // Under this condition a resize will trigger its own resize, causing an error.
5520
- if (size < settings.containerWidth) {
5521
- return;
5521
+ settings.resizeObserver = new ResizeObserver(function (e) {
5522
+ if (first) {
5523
+ first = false;
5524
+ }
5525
+ else {
5526
+ resize();
5522
5527
  }
5523
-
5524
- resize();
5525
5528
  });
5526
- settings.resizeObserver.observe(settings.nTableWrapper);
5529
+
5530
+ settings.resizeObserver.observe(resizer[0]);
5527
5531
  }
5528
5532
  else {
5529
5533
  // For old browsers, the best we can do is listen for a window resize
@@ -5534,6 +5538,17 @@ function _fnCalculateColumnWidths ( settings )
5534
5538
  }
5535
5539
  }
5536
5540
 
5541
+ /**
5542
+ * Get the width of the DataTables wrapper element
5543
+ *
5544
+ * @param {*} settings DataTables settings object
5545
+ * @returns Width
5546
+ */
5547
+ function _fnWrapperWidth(settings) {
5548
+ return $(settings.nTableWrapper).is(':visible')
5549
+ ? $(settings.nTableWrapper).width()
5550
+ : 0;
5551
+ }
5537
5552
 
5538
5553
  /**
5539
5554
  * Get the maximum strlen for each data column
@@ -5844,10 +5859,14 @@ function _fnSort ( oSettings, col, dir )
5844
5859
  displayMaster = oSettings.aiDisplayMaster,
5845
5860
  aSort;
5846
5861
 
5862
+ // Make sure the columns all have types defined
5863
+ _fnColumnTypes(oSettings);
5864
+
5847
5865
  // Allow a specific column to be sorted, which will _not_ alter the display
5848
5866
  // master
5849
5867
  if (col !== undefined) {
5850
5868
  var srcCol = oSettings.aoColumns[col];
5869
+
5851
5870
  aSort = [{
5852
5871
  src: col,
5853
5872
  col: col,
@@ -8896,6 +8915,10 @@ _api_registerPlural( 'columns().indexes()', 'column().index()', function ( type
8896
8915
 
8897
8916
  _api_register( 'columns.adjust()', function () {
8898
8917
  return this.iterator( 'table', function ( settings ) {
8918
+ // Force a column sizing to happen with a manual call - otherwise it can skip
8919
+ // if the size hasn't changed
8920
+ settings.containerWidth = -1;
8921
+
8899
8922
  _fnAdjustColumnSizing( settings );
8900
8923
  }, 1 );
8901
8924
  } );
@@ -9787,12 +9810,14 @@ _api_register( 'ready()', function ( fn ) {
9787
9810
  // Function to run either once the table becomes ready or
9788
9811
  // immediately if it is already ready.
9789
9812
  return this.tables().every(function () {
9813
+ var api = this;
9814
+
9790
9815
  if (this.context[0]._bInitComplete) {
9791
- fn.call(this);
9816
+ fn.call(api);
9792
9817
  }
9793
9818
  else {
9794
9819
  this.on('init.dt.DT', function () {
9795
- fn.call(this);
9820
+ fn.call(api);
9796
9821
  });
9797
9822
  }
9798
9823
  } );
@@ -9848,20 +9873,37 @@ _api_register( 'destroy()', function ( remove ) {
9848
9873
  jqTable.append( tfoot );
9849
9874
  }
9850
9875
 
9876
+ // Clean up the header
9877
+ $(thead).find('span.dt-column-order').remove();
9878
+ $(thead).find('span.dt-column-title').each(function () {
9879
+ var title = $(this).html();
9880
+ $(this).parent().append(title);
9881
+ $(this).remove();
9882
+ });
9883
+
9851
9884
  settings.colgroup.remove();
9852
9885
 
9853
9886
  settings.aaSorting = [];
9854
9887
  settings.aaSortingFixed = [];
9855
9888
  _fnSortingClasses( settings );
9856
9889
 
9890
+ $(jqTable).find('th, td').removeClass(
9891
+ $.map(DataTable.ext.type.className, function (v) {
9892
+ return v;
9893
+ }).join(' ')
9894
+ );
9895
+
9857
9896
  $('th, td', thead)
9858
9897
  .removeClass(
9898
+ orderClasses.none + ' ' +
9859
9899
  orderClasses.canAsc + ' ' +
9860
9900
  orderClasses.canDesc + ' ' +
9861
9901
  orderClasses.isAsc + ' ' +
9862
9902
  orderClasses.isDesc
9863
9903
  )
9864
- .css('width', '');
9904
+ .css('width', '')
9905
+ .removeAttr('data-dt-column')
9906
+ .removeAttr('aria-sort');
9865
9907
 
9866
9908
  // Add the TR elements back into the table in their original order
9867
9909
  jqTbody.children().detach();
@@ -9949,7 +9991,7 @@ _api_register( 'i18n()', function ( token, def, plural ) {
9949
9991
  * @type string
9950
9992
  * @default Version number
9951
9993
  */
9952
- DataTable.version = "2.2.0";
9994
+ DataTable.version = "2.2.2";
9953
9995
 
9954
9996
  /**
9955
9997
  * Private data store, containing all of the settings objects that are
@@ -12058,7 +12100,7 @@ DataTable.models.oSettings = {
12058
12100
  resizeObserver: null,
12059
12101
 
12060
12102
  /** Keep a record of the last size of the container, so we can skip duplicates */
12061
- containerWidth: 0
12103
+ containerWidth: -1
12062
12104
  };
12063
12105
 
12064
12106
  /**
@@ -12990,16 +13032,16 @@ $.extend( true, DataTable.ext.renderer, {
12990
13032
  cell.removeAttr('aria-sort');
12991
13033
  }
12992
13034
 
12993
- cell.attr('aria-label', orderable
12994
- ? col.ariaTitle + ctx.api.i18n('oAria.orderable' + ariaType)
12995
- : col.ariaTitle
12996
- );
12997
-
12998
13035
  // Make the headers tab-able for keyboard navigation
12999
13036
  if (orderable) {
13000
13037
  var orderSpan = cell.find('.dt-column-order');
13001
13038
 
13002
- orderSpan.attr('role', 'button');
13039
+ orderSpan
13040
+ .attr('role', 'button')
13041
+ .attr('aria-label', orderable
13042
+ ? col.ariaTitle + ctx.api.i18n('oAria.orderable' + ariaType)
13043
+ : col.ariaTitle
13044
+ );
13003
13045
 
13004
13046
  if (tabIndex !== -1) {
13005
13047
  orderSpan.attr('tabindex', tabIndex);
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.2.0",
7
+ "version": "2.2.2",
8
8
  "files": [
9
9
  "js/**/*.js",
10
10
  "js/**/*.mjs",