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/Readme.md CHANGED
@@ -1,6 +1,6 @@
1
- # DataTables for jQuery
1
+ # DataTables
2
2
 
3
- This package contains distribution files for the [DataTables library](https://datatables.net) for [jQuery](http://jquery.com/). Only the core software for this library is contained in this package - to be correctly styled, a styling package for DataTables must also be included. Styling options include DataTable's native styling, [Bootstrap](http://getbootstrap.com) and [Foundation](http://foundation.zurb.com/).
3
+ This package contains distribution files for the [DataTables table enhancement library](https://datatables.net). Only the core software for this library is contained in this package - to be correctly styled, a styling package for DataTables must also be included (e.g. default, Bootstrap, Bulma, Foundation or others) - please see the [npm installation documentation on the DataTables site](https://datatables.net/manual/installation#Node.js-/-NPM) for full details.
4
4
 
5
5
  DataTables is a table enhancing library which adds features such as paging, ordering, search, scrolling and many more to a static HTML page. A comprehensive API is also available that can be used to manipulate the table. Please refer to the [DataTables web-site](//datatables.net) for a full range of documentation and examples.
6
6
 
@@ -9,29 +9,34 @@ DataTables is a table enhancing library which adds features such as paging, orde
9
9
 
10
10
  ### Browser
11
11
 
12
- For inclusion of this library using a standard `<script>` tag, rather than using this package, it is recommended that you use the [DataTables download builder](//datatables.net/download) which can create CDN or locally hosted packages \for you, will all dependencies satisfied.
12
+ To use DataTables with a simple `<script>` tag, rather than using this package, it is recommended that you use the [DataTables download builder](//datatables.net/download) which can create CDN or locally hosted packages for you, will all dependencies satisfied.
13
13
 
14
14
  ### npm
15
15
 
16
+ For installation via npm, yarn and other similar package managers, install this package with your package manager - e.g.:
17
+
16
18
  ```
17
19
  npm install datatables.net
18
20
  ```
19
21
 
20
- ES3 Syntax
21
- ```
22
- var $ = require( 'jquery' );
23
- require( 'datatables.net' )( window, $ );
24
- ```
22
+ Then, to load and initialise DataTables in your code use:
25
23
 
26
- ES6 Syntax
27
24
  ```
28
- import 'datatables.net'
25
+ import DataTable from 'datatables.net';
26
+
27
+ new DataTable('#myTable', {
28
+ // initalisation options
29
+ });
29
30
  ```
30
31
 
31
- ### bower
32
+ If you are using an old version of Node or a CommonJS loader, you might need to use the `require` syntax:
32
33
 
33
34
  ```
34
- bower install --save datatables.net
35
+ const DataTable = require('datatables.net');
36
+
37
+ new DataTable('#myTable', {
38
+ // initalisation options
39
+ });
35
40
  ```
36
41
 
37
42
 
@@ -45,7 +50,6 @@ Full documentation of the DataTables options, API and plug-in interface are avai
45
50
 
46
51
  Support for DataTables is available through the [DataTables forums](//datatables.net/forums) and [commercial support options](//datatables.net/support) are available.
47
52
 
48
-
49
53
  ### Contributing
50
54
 
51
55
  If you are thinking of contributing code to DataTables, first of all, thank you! All fixes, patches and enhancements to DataTables are very warmly welcomed. This repository is a distribution repo, so patches and issues sent to this repo will not be accepted. Instead, please direct pull requests to the [DataTables/DataTablesSrc](http://github.com/DataTables/DataTablesSrc). For issues / bugs, please direct your questions to the [DataTables forums](//datatables.net/forums).
package/js/dataTables.js 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
 
@@ -5350,6 +5350,14 @@
5350
5350
  i, column, columnIdx;
5351
5351
 
5352
5352
  var styleWidth = table.style.width;
5353
+ var containerWidth = _fnWrapperWidth(settings);
5354
+
5355
+ // Don't re-run for the same width as the last time
5356
+ if (containerWidth === settings.containerWidth) {
5357
+ return false;
5358
+ }
5359
+
5360
+ settings.containerWidth = containerWidth;
5353
5361
 
5354
5362
  // If there is no width applied as a CSS style or as an attribute, we assume that
5355
5363
  // the width is intended to be 100%, which is usually is in CSS, but it is very
@@ -5477,15 +5485,15 @@
5477
5485
 
5478
5486
  // If there is no width attribute or style, then allow the table to
5479
5487
  // collapse
5480
- if ( tmpTable.width() < tableContainer.clientWidth && tableWidthAttr ) {
5481
- tmpTable.width( tableContainer.clientWidth );
5488
+ if ( tmpTable.outerWidth() < tableContainer.clientWidth && tableWidthAttr ) {
5489
+ tmpTable.outerWidth( tableContainer.clientWidth );
5482
5490
  }
5483
5491
  }
5484
5492
  else if ( scrollY ) {
5485
- tmpTable.width( tableContainer.clientWidth );
5493
+ tmpTable.outerWidth( tableContainer.clientWidth );
5486
5494
  }
5487
5495
  else if ( tableWidthAttr ) {
5488
- tmpTable.width( tableWidthAttr );
5496
+ tmpTable.outerWidth( tableWidthAttr );
5489
5497
  }
5490
5498
 
5491
5499
  // Get the width of each column in the constructed table
@@ -5518,47 +5526,43 @@
5518
5526
  }
5519
5527
 
5520
5528
  if ( (tableWidthAttr || scrollX) && ! settings._reszEvt ) {
5521
- var wrapperWidth = function () {
5522
- return $(settings.nTableWrapper).is(':visible')
5523
- ? $(settings.nTableWrapper).width()
5524
- : 0;
5525
- }
5526
-
5527
- settings.containerWidth = wrapperWidth();
5528
-
5529
5529
  var resize = DataTable.util.throttle( function () {
5530
- var newWidth = wrapperWidth();
5530
+ var newWidth = _fnWrapperWidth(settings);
5531
5531
 
5532
- // Don't do it if destroying, is the same size as last time, or the container
5533
- // width is 0
5534
- if (
5535
- ! settings.bDestroying &&
5536
- settings.containerWidth !== newWidth &&
5537
- newWidth !== 0
5538
- ) {
5539
- // Do a resize
5532
+ // Don't do it if destroying or the container width is 0
5533
+ if (! settings.bDestroying && newWidth !== 0) {
5540
5534
  _fnAdjustColumnSizing( settings );
5541
- settings.containerWidth = newWidth;
5542
5535
  }
5543
5536
  } );
5544
5537
 
5545
5538
  // For browsers that support it (~2020 onwards for wide support) we can watch for the
5546
5539
  // container changing width.
5547
5540
  if (window.ResizeObserver) {
5548
- settings.resizeObserver = new ResizeObserver(function (e) {
5549
- var box = e[0].contentBoxSize;
5550
- var size = Array.isArray(box)
5551
- ? box[0].inlineSize // Spec
5552
- : box.inlineSize; // Old Firefox
5541
+ // This is a tricky beast - if the element is visible when `.observe()` is called,
5542
+ // then the callback is immediately run. Which we don't want. If the element isn't
5543
+ // visible, then it isn't run, but we want it to run when it is then made visible.
5544
+ // This flag allows the above to be satisfied.
5545
+ var first = $(settings.nTableWrapper).is(':visible');
5546
+
5547
+ // Use an empty div to attach the observer so it isn't impacted by height changes
5548
+ var resizer = $('<div>')
5549
+ .css({
5550
+ width: '100%',
5551
+ height: 0
5552
+ })
5553
+ .addClass('dt-autosize')
5554
+ .appendTo(settings.nTableWrapper);
5553
5555
 
5554
- // Under this condition a resize will trigger its own resize, causing an error.
5555
- if (size < settings.containerWidth) {
5556
- return;
5556
+ settings.resizeObserver = new ResizeObserver(function (e) {
5557
+ if (first) {
5558
+ first = false;
5559
+ }
5560
+ else {
5561
+ resize();
5557
5562
  }
5558
-
5559
- resize();
5560
5563
  });
5561
- settings.resizeObserver.observe(settings.nTableWrapper);
5564
+
5565
+ settings.resizeObserver.observe(resizer[0]);
5562
5566
  }
5563
5567
  else {
5564
5568
  // For old browsers, the best we can do is listen for a window resize
@@ -5569,6 +5573,17 @@
5569
5573
  }
5570
5574
  }
5571
5575
 
5576
+ /**
5577
+ * Get the width of the DataTables wrapper element
5578
+ *
5579
+ * @param {*} settings DataTables settings object
5580
+ * @returns Width
5581
+ */
5582
+ function _fnWrapperWidth(settings) {
5583
+ return $(settings.nTableWrapper).is(':visible')
5584
+ ? $(settings.nTableWrapper).width()
5585
+ : 0;
5586
+ }
5572
5587
 
5573
5588
  /**
5574
5589
  * Get the maximum strlen for each data column
@@ -5879,10 +5894,14 @@
5879
5894
  displayMaster = oSettings.aiDisplayMaster,
5880
5895
  aSort;
5881
5896
 
5897
+ // Make sure the columns all have types defined
5898
+ _fnColumnTypes(oSettings);
5899
+
5882
5900
  // Allow a specific column to be sorted, which will _not_ alter the display
5883
5901
  // master
5884
5902
  if (col !== undefined) {
5885
5903
  var srcCol = oSettings.aoColumns[col];
5904
+
5886
5905
  aSort = [{
5887
5906
  src: col,
5888
5907
  col: col,
@@ -8931,6 +8950,10 @@
8931
8950
 
8932
8951
  _api_register( 'columns.adjust()', function () {
8933
8952
  return this.iterator( 'table', function ( settings ) {
8953
+ // Force a column sizing to happen with a manual call - otherwise it can skip
8954
+ // if the size hasn't changed
8955
+ settings.containerWidth = -1;
8956
+
8934
8957
  _fnAdjustColumnSizing( settings );
8935
8958
  }, 1 );
8936
8959
  } );
@@ -9822,12 +9845,14 @@
9822
9845
  // Function to run either once the table becomes ready or
9823
9846
  // immediately if it is already ready.
9824
9847
  return this.tables().every(function () {
9848
+ var api = this;
9849
+
9825
9850
  if (this.context[0]._bInitComplete) {
9826
- fn.call(this);
9851
+ fn.call(api);
9827
9852
  }
9828
9853
  else {
9829
9854
  this.on('init.dt.DT', function () {
9830
- fn.call(this);
9855
+ fn.call(api);
9831
9856
  });
9832
9857
  }
9833
9858
  } );
@@ -9883,20 +9908,37 @@
9883
9908
  jqTable.append( tfoot );
9884
9909
  }
9885
9910
 
9911
+ // Clean up the header
9912
+ $(thead).find('span.dt-column-order').remove();
9913
+ $(thead).find('span.dt-column-title').each(function () {
9914
+ var title = $(this).html();
9915
+ $(this).parent().append(title);
9916
+ $(this).remove();
9917
+ });
9918
+
9886
9919
  settings.colgroup.remove();
9887
9920
 
9888
9921
  settings.aaSorting = [];
9889
9922
  settings.aaSortingFixed = [];
9890
9923
  _fnSortingClasses( settings );
9891
9924
 
9925
+ $(jqTable).find('th, td').removeClass(
9926
+ $.map(DataTable.ext.type.className, function (v) {
9927
+ return v;
9928
+ }).join(' ')
9929
+ );
9930
+
9892
9931
  $('th, td', thead)
9893
9932
  .removeClass(
9933
+ orderClasses.none + ' ' +
9894
9934
  orderClasses.canAsc + ' ' +
9895
9935
  orderClasses.canDesc + ' ' +
9896
9936
  orderClasses.isAsc + ' ' +
9897
9937
  orderClasses.isDesc
9898
9938
  )
9899
- .css('width', '');
9939
+ .css('width', '')
9940
+ .removeAttr('data-dt-column')
9941
+ .removeAttr('aria-sort');
9900
9942
 
9901
9943
  // Add the TR elements back into the table in their original order
9902
9944
  jqTbody.children().detach();
@@ -9984,7 +10026,7 @@
9984
10026
  * @type string
9985
10027
  * @default Version number
9986
10028
  */
9987
- DataTable.version = "2.2.0";
10029
+ DataTable.version = "2.2.2";
9988
10030
 
9989
10031
  /**
9990
10032
  * Private data store, containing all of the settings objects that are
@@ -12093,7 +12135,7 @@
12093
12135
  resizeObserver: null,
12094
12136
 
12095
12137
  /** Keep a record of the last size of the container, so we can skip duplicates */
12096
- containerWidth: 0
12138
+ containerWidth: -1
12097
12139
  };
12098
12140
 
12099
12141
  /**
@@ -13025,16 +13067,16 @@
13025
13067
  cell.removeAttr('aria-sort');
13026
13068
  }
13027
13069
 
13028
- cell.attr('aria-label', orderable
13029
- ? col.ariaTitle + ctx.api.i18n('oAria.orderable' + ariaType)
13030
- : col.ariaTitle
13031
- );
13032
-
13033
13070
  // Make the headers tab-able for keyboard navigation
13034
13071
  if (orderable) {
13035
13072
  var orderSpan = cell.find('.dt-column-order');
13036
13073
 
13037
- orderSpan.attr('role', 'button');
13074
+ orderSpan
13075
+ .attr('role', 'button')
13076
+ .attr('aria-label', orderable
13077
+ ? col.ariaTitle + ctx.api.i18n('oAria.orderable' + ariaType)
13078
+ : col.ariaTitle
13079
+ );
13038
13080
 
13039
13081
  if (tabIndex !== -1) {
13040
13082
  orderSpan.attr('tabindex', tabIndex);