datatables.net-select 2.0.4 → 2.1.0

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.
@@ -1,4 +1,4 @@
1
- /*! Select for DataTables 2.0.4
1
+ /*! Select for DataTables 2.1.0
2
2
  * © SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
 
@@ -56,7 +56,7 @@ DataTable.select.classes = {
56
56
  checkbox: 'dt-select-checkbox'
57
57
  };
58
58
 
59
- DataTable.select.version = '2.0.4';
59
+ DataTable.select.version = '2.1.0';
60
60
 
61
61
  DataTable.select.init = function (dt) {
62
62
  var ctx = dt.settings()[0];
@@ -126,6 +126,7 @@ DataTable.select.init = function (dt) {
126
126
  var style = 'api';
127
127
  var blurable = false;
128
128
  var toggleable = true;
129
+ var selectable = null;
129
130
  var info = true;
130
131
  var selector = 'td, th';
131
132
  var className = 'selected';
@@ -182,6 +183,10 @@ DataTable.select.init = function (dt) {
182
183
  if (opts.headerCheckbox !== undefined) {
183
184
  headerCheckbox = opts.headerCheckbox;
184
185
  }
186
+
187
+ if (opts.selectable !== undefined) {
188
+ selectable = opts.selectable;
189
+ }
185
190
  }
186
191
 
187
192
  dt.select.selector(selector);
@@ -190,6 +195,7 @@ DataTable.select.init = function (dt) {
190
195
  dt.select.blurable(blurable);
191
196
  dt.select.toggleable(toggleable);
192
197
  dt.select.info(info);
198
+ dt.select.selectable(selectable);
193
199
  ctx._select.className = className;
194
200
 
195
201
  // If the init options haven't enabled select, but there is a selectable
@@ -199,11 +205,9 @@ DataTable.select.init = function (dt) {
199
205
  }
200
206
 
201
207
  // Insert a checkbox into the header if needed - might need to wait
202
- // for init complete, or it might already be done
208
+ // for init complete
203
209
  if (headerCheckbox || headerCheckbox === 'select-page' || headerCheckbox === 'select-all') {
204
- initCheckboxHeader(dt, headerCheckbox);
205
-
206
- dt.on('init', function () {
210
+ dt.ready(function () {
207
211
  initCheckboxHeader(dt, headerCheckbox);
208
212
  });
209
213
  }
@@ -549,6 +553,15 @@ function eventTrigger(api, type, args, any) {
549
553
  $(api.table().node()).trigger(type, args);
550
554
  }
551
555
 
556
+ /**
557
+ * Determine if a column is a checkbox column
558
+ * @param {*} col DataTables column object
559
+ * @returns
560
+ */
561
+ function isCheckboxColumn(col) {
562
+ return col.mRender && col.mRender._name === 'selectCheckbox';
563
+ }
564
+
552
565
  /**
553
566
  * Update the information element of the DataTable showing information about the
554
567
  * items selected. This is done by adding tags to the existing text
@@ -561,9 +574,13 @@ function info(api, node) {
561
574
  return;
562
575
  }
563
576
 
564
- var rows = api.rows({ selected: true }).flatten().length;
565
- var columns = api.columns({ selected: true }).flatten().length;
566
- var cells = api.cells({ selected: true }).flatten().length;
577
+ // If _select_set has any length, then ids are available and should be used
578
+ // as the counter. Otherwise use the API to workout how many rows are
579
+ // selected.
580
+ var rowSetLength = api.settings()[0]._select_set.length;
581
+ var rows = rowSetLength ? rowSetLength : api.rows({ selected: true }).count();
582
+ var columns = api.columns({ selected: true }).count();
583
+ var cells = api.cells({ selected: true }).count();
567
584
 
568
585
  var add = function (el, name, num) {
569
586
  el.append(
@@ -603,9 +620,18 @@ function info(api, node) {
603
620
  * @param {*} headerCheckbox the header checkbox option
604
621
  */
605
622
  function initCheckboxHeader( dt, headerCheckbox ) {
623
+ var dtSettings = dt.settings()[0];
624
+ var dtInternalColumns = dtSettings.aoColumns;
625
+
606
626
  // Find any checkbox column(s)
607
- dt.columns('.dt-select').every(function () {
608
- var header = this.header();
627
+ dt.columns().iterator('column', function (s, idx) {
628
+ var col = dtInternalColumns[idx];
629
+
630
+ // Checkbox columns have a rendering function with a given name
631
+ if (! isCheckboxColumn(col)) {
632
+ return;
633
+ }
634
+ var header = dt.column(idx).header();
609
635
 
610
636
  if (! $('input', header).length) {
611
637
  // If no checkbox yet, insert one
@@ -619,33 +645,36 @@ function initCheckboxHeader( dt, headerCheckbox ) {
619
645
  .on('change', function () {
620
646
  if (this.checked) {
621
647
  if (headerCheckbox == 'select-page') {
622
- dt.rows({page: 'current'}).select()
648
+ dt.rows({page: 'current'}).select();
623
649
  } else {
624
650
  dt.rows({search: 'applied'}).select();
625
651
  }
626
652
  }
627
653
  else {
628
- dt.rows({selected: true}).deselect();
654
+ if (headerCheckbox == 'select-page') {
655
+ dt.rows({page: 'current', selected: true}).deselect();
656
+ }
657
+ else {
658
+ dt.rows({selected: true}).deselect();
659
+ }
629
660
  }
630
661
  })
631
662
  .on('click', function (e) {
632
663
  e.stopPropagation();
633
664
  });
634
-
665
+
635
666
  // Update the header checkbox's state when the selection in the
636
667
  // table changes
637
668
  dt.on('draw select deselect', function (e, pass, type) {
638
669
  if (type === 'row' || ! type) {
639
- var count = dt.rows({selected: true}).count();
640
- var search = dt.rows({search: 'applied', selected: true}).count();
641
- var available = headerCheckbox == 'select-page' ? dt.rows({page: 'current'}).count() : dt.rows({search: 'applied'}).count();
670
+ var nums = headerCheckboxState(dt, headerCheckbox);
642
671
 
643
- if (search && search <= count && search === available) {
672
+ if (nums.search && nums.search <= nums.count && nums.search === nums.available) {
644
673
  input
645
674
  .prop('checked', true)
646
675
  .prop('indeterminate', false);
647
676
  }
648
- else if (search === 0 && count === 0) {
677
+ else if (nums.search === 0 && nums.count === 0) {
649
678
  input
650
679
  .prop('checked', false)
651
680
  .prop('indeterminate', false);
@@ -661,6 +690,54 @@ function initCheckboxHeader( dt, headerCheckbox ) {
661
690
  });
662
691
  }
663
692
 
693
+ /**
694
+ * Determine the counts used to define the header checkbox's state
695
+ *
696
+ * @param {*} dt DT API
697
+ * @param {*} headerCheckbox Configuration for what the header checkbox does
698
+ * @returns Counts object
699
+ */
700
+ function headerCheckboxState(dt, headerCheckbox) {
701
+ var ctx = dt.settings()[0];
702
+ var selectable = ctx._select.selectable;
703
+ var available = 0;
704
+ var count = headerCheckbox == 'select-page'
705
+ ? dt.rows({page: 'current', selected: true}).count()
706
+ : dt.rows({selected: true}).count();
707
+ var search = headerCheckbox == 'select-page'
708
+ ? dt.rows({page: 'current', selected: true}).count()
709
+ : dt.rows({search: 'applied', selected: true}).count();
710
+
711
+ if (! selectable) {
712
+ available = headerCheckbox == 'select-page'
713
+ ? dt.rows({page: 'current'}).count()
714
+ : dt.rows({search: 'applied'}).count();
715
+ }
716
+ else {
717
+ // Need to count how many rows are actually selectable to know if all selectable
718
+ // rows are selected or not
719
+ var indexes = headerCheckbox == 'select-page'
720
+ ? dt.rows({page: 'current'}).indexes()
721
+ : dt.rows({search: 'applied'}).indexes();
722
+
723
+ for (var i=0 ; i<indexes.length ; i++) {
724
+ // For speed I use the internal DataTables object.
725
+ var rowInternal = ctx.aoData[indexes[i]];
726
+ var result = selectable(rowInternal._aData, rowInternal.nTr, indexes[i]);
727
+
728
+ if (result) {
729
+ available++;
730
+ }
731
+ }
732
+ }
733
+
734
+ return {
735
+ available: available,
736
+ count: count,
737
+ search: search
738
+ }
739
+ }
740
+
664
741
  /**
665
742
  * Initialisation of a new table. Attach event handlers and callbacks to allow
666
743
  * Select to operate correctly.
@@ -675,6 +752,9 @@ function init(ctx) {
675
752
  var api = new DataTable.Api(ctx);
676
753
  ctx._select_init = true;
677
754
 
755
+ // _select_set contains a list of the ids of all rows that are selected
756
+ ctx._select_set = [];
757
+
678
758
  // Row callback so that classes can be added to rows and cells if the item
679
759
  // was selected before the element was created. This will happen with the
680
760
  // `deferRender` option enabled.
@@ -685,9 +765,15 @@ function init(ctx) {
685
765
  ctx.aoRowCreatedCallback.push(function (row, data, index) {
686
766
  var i, ien;
687
767
  var d = ctx.aoData[index];
768
+ var id = api.row(index).id();
688
769
 
689
770
  // Row
690
- if (d._select_selected) {
771
+ if (
772
+ d._select_selected ||
773
+ (id !== 'undefined' && ctx._select_set.includes(id))
774
+ ) {
775
+ d._select_selected = true;
776
+
691
777
  $(row)
692
778
  .addClass(ctx._select.className)
693
779
  .find('input.' + checkboxClass(true)).prop('checked', true);
@@ -706,46 +792,7 @@ function init(ctx) {
706
792
  }
707
793
  );
708
794
 
709
- // On Ajax reload we want to reselect all rows which are currently selected,
710
- // if there is an rowId (i.e. a unique value to identify each row with)
711
- api.on('preXhr.dt.dtSelect', function (e, settings) {
712
- if (settings !== api.settings()[0]) {
713
- // Not triggered by our DataTable!
714
- return;
715
- }
716
-
717
- // note that column selection doesn't need to be cached and then
718
- // reselected, as they are already selected
719
- var rows = api
720
- .rows({ selected: true })
721
- .ids(true)
722
- .filter(function (d) {
723
- return d !== undefined;
724
- });
725
-
726
- var cells = api
727
- .cells({ selected: true })
728
- .eq(0)
729
- .map(function (cellIdx) {
730
- var id = api.row(cellIdx.row).id(true);
731
- return id ? { row: id, column: cellIdx.column } : undefined;
732
- })
733
- .filter(function (d) {
734
- return d !== undefined;
735
- });
736
-
737
- // On the next draw, reselect the currently selected items
738
- api.one('draw.dt.dtSelect', function () {
739
- api.rows(rows).select();
740
-
741
- // `cells` is not a cell index selector, so it needs a loop
742
- if (cells.any()) {
743
- cells.each(function (id) {
744
- api.cells(id.row, id.column).select();
745
- });
746
- }
747
- });
748
- });
795
+ _cumulativeEvents(api);
749
796
 
750
797
  // Update the table information element with selected item summary
751
798
  api.on('info.dt', function (e, ctx, node) {
@@ -918,6 +965,57 @@ function _safeId(node) {
918
965
  return node.id.replace(/[^a-zA-Z0-9\-\_]/g, '-');
919
966
  }
920
967
 
968
+ /**
969
+ * Set up event handlers for cumulative selection
970
+ *
971
+ * @param {*} api DT API instance
972
+ */
973
+ function _cumulativeEvents(api) {
974
+ // Add event listeners to add / remove from the _select_set
975
+ api.on('select', function (e, dt, type, indexes) {
976
+ // Only support for rows at the moment
977
+ if (type !== 'row') {
978
+ return;
979
+ }
980
+
981
+ var ctx = api.settings()[0];
982
+
983
+ _add(api, ctx._select_set, indexes);
984
+ });
985
+
986
+ api.on('deselect', function (e, dt, type, indexes) {
987
+ // Only support for rows at the moment
988
+ if (type !== 'row') {
989
+ return;
990
+ }
991
+
992
+ var ctx = api.settings()[0];
993
+
994
+ _remove(api, ctx._select_set, indexes);
995
+ });
996
+ }
997
+
998
+ function _add(api, arr, indexes) {
999
+ for (var i=0 ; i<indexes.length ; i++) {
1000
+ var id = api.row(indexes[i]).id();
1001
+
1002
+ if (id && id !== 'undefined' && ! arr.includes(id)) {
1003
+ arr.push(id);
1004
+ }
1005
+ }
1006
+ }
1007
+
1008
+ function _remove(api, arr, indexes) {
1009
+ for (var i=0 ; i<indexes.length ; i++) {
1010
+ var id = api.row(indexes[i]).id();
1011
+ var idx = arr.indexOf(id);
1012
+
1013
+ if (idx !== -1) {
1014
+ arr.splice(idx, 1);
1015
+ }
1016
+ }
1017
+ }
1018
+
921
1019
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
922
1020
  * DataTables selectors
923
1021
  */
@@ -1066,10 +1164,15 @@ apiRegister('select.style()', function (style) {
1066
1164
  // Add / remove mouse event handlers. They aren't required when only
1067
1165
  // API selection is available
1068
1166
  var dt = new DataTable.Api(ctx);
1069
- disableMouseSelection(dt);
1070
1167
 
1071
1168
  if (style !== 'api') {
1072
- enableMouseSelection(dt);
1169
+ dt.ready(function () {
1170
+ disableMouseSelection(dt);
1171
+ enableMouseSelection(dt);
1172
+ });
1173
+ }
1174
+ else {
1175
+ disableMouseSelection(dt);
1073
1176
  }
1074
1177
 
1075
1178
  eventTrigger(new DataTable.Api(ctx), 'selectStyle', [style]);
@@ -1082,16 +1185,36 @@ apiRegister('select.selector()', function (selector) {
1082
1185
  }
1083
1186
 
1084
1187
  return this.iterator('table', function (ctx) {
1085
- disableMouseSelection(new DataTable.Api(ctx));
1188
+ var dt = new DataTable.Api(ctx);
1189
+ var style = ctx._select.style;
1190
+
1191
+ disableMouseSelection(dt);
1086
1192
 
1087
1193
  ctx._select.selector = selector;
1088
1194
 
1089
- if (ctx._select.style !== 'api') {
1090
- enableMouseSelection(new DataTable.Api(ctx));
1195
+ if (style && style !== 'api') {
1196
+ dt.ready(function () {
1197
+ disableMouseSelection(dt);
1198
+ enableMouseSelection(dt);
1199
+ });
1200
+ }
1201
+ else {
1202
+ disableMouseSelection(dt);
1091
1203
  }
1092
1204
  });
1093
1205
  });
1094
1206
 
1207
+ apiRegister('select.selectable()', function (set) {
1208
+ let ctx = this.context[0];
1209
+
1210
+ if (set) {
1211
+ ctx._select.selectable = set;
1212
+ return this;
1213
+ }
1214
+
1215
+ return ctx._select.selectable;
1216
+ });
1217
+
1095
1218
  apiRegister('select.last()', function (set) {
1096
1219
  let ctx = this.context[0];
1097
1220
 
@@ -1103,8 +1226,17 @@ apiRegister('select.last()', function (set) {
1103
1226
  return ctx._select_lastCell;
1104
1227
  });
1105
1228
 
1229
+ apiRegister('select.cumulative()', function () {
1230
+ let ctx = this.context[0];
1231
+
1232
+ return ctx && ctx._select_set
1233
+ ? ctx._select_set
1234
+ : [];
1235
+ });
1236
+
1106
1237
  apiRegisterPlural('rows().select()', 'row().select()', function (select) {
1107
1238
  var api = this;
1239
+ var selectedIndexes = [];
1108
1240
 
1109
1241
  if (select === false) {
1110
1242
  return this.deselect();
@@ -1119,9 +1251,20 @@ apiRegisterPlural('rows().select()', 'row().select()', function (select) {
1119
1251
  var dtData = ctx.aoData[idx];
1120
1252
  var dtColumns = ctx.aoColumns;
1121
1253
 
1254
+ if (ctx._select.selectable) {
1255
+ var result = ctx._select.selectable(dtData._aData, dtData.nTr, idx);
1256
+
1257
+ if (result === false) {
1258
+ // Not selectable - do nothing
1259
+ return;
1260
+ }
1261
+ }
1262
+
1122
1263
  $(dtData.nTr).addClass(ctx._select.className);
1123
1264
  dtData._select_selected = true;
1124
1265
 
1266
+ selectedIndexes.push(idx);
1267
+
1125
1268
  for (var i=0 ; i<dtColumns.length ; i++) {
1126
1269
  var col = dtColumns[i];
1127
1270
 
@@ -1130,7 +1273,7 @@ apiRegisterPlural('rows().select()', 'row().select()', function (select) {
1130
1273
  api.columns().types()
1131
1274
  }
1132
1275
 
1133
- if (col.sType === 'select-checkbox') {
1276
+ if (isCheckboxColumn(col)) {
1134
1277
  var cells = dtData.anCells;
1135
1278
 
1136
1279
  // Make sure the checkbox shows the right state
@@ -1146,8 +1289,8 @@ apiRegisterPlural('rows().select()', 'row().select()', function (select) {
1146
1289
  }
1147
1290
  });
1148
1291
 
1149
- this.iterator('table', function (ctx, i) {
1150
- eventTrigger(api, 'select', ['row', api[i]], true);
1292
+ this.iterator('table', function (ct) {
1293
+ eventTrigger(api, 'select', ['row', selectedIndexes], true);
1151
1294
  });
1152
1295
 
1153
1296
  return this;
@@ -1264,7 +1407,7 @@ apiRegisterPlural('rows().deselect()', 'row().deselect()', function () {
1264
1407
  api.columns().types()
1265
1408
  }
1266
1409
 
1267
- if (col.sType === 'select-checkbox') {
1410
+ if (isCheckboxColumn(col)) {
1268
1411
  var cells = dtData.anCells;
1269
1412
 
1270
1413
  // Make sure the checkbox shows the right state
@@ -1509,6 +1652,8 @@ $.each(['Row', 'Column', 'Cell'], function (i, item) {
1509
1652
  init: function (dt) {
1510
1653
  var that = this;
1511
1654
 
1655
+ this.active(dt.select.items() === lc);
1656
+
1512
1657
  dt.on('selectItems.dt.DT', function (e, ctx, items) {
1513
1658
  that.active(items === lc);
1514
1659
  });
@@ -1517,7 +1662,7 @@ $.each(['Row', 'Column', 'Cell'], function (i, item) {
1517
1662
  });
1518
1663
 
1519
1664
  // Note that DataTables 2.1 has more robust type detection, but we retain
1520
- // backwards compatbility with 2.0 for the moment.
1665
+ // backwards compatibility with 2.0 for the moment.
1521
1666
  DataTable.type('select-checkbox', {
1522
1667
  className: 'dt-select',
1523
1668
  detect: DataTable.versionCheck('2.1')
@@ -1529,7 +1674,7 @@ DataTable.type('select-checkbox', {
1529
1674
  return false; // no op
1530
1675
  },
1531
1676
  init: function (settings, col, idx) {
1532
- return col.mRender && col.mRender.name === 'selectCheckbox';
1677
+ return isCheckboxColumn(col);
1533
1678
  }
1534
1679
  }
1535
1680
  : function (data) {
@@ -1555,12 +1700,22 @@ DataTable.render.select = function (valueProp, nameProp) {
1555
1700
  var valueFn = valueProp ? DataTable.util.get(valueProp) : null;
1556
1701
  var nameFn = nameProp ? DataTable.util.get(nameProp) : null;
1557
1702
 
1558
- return function selectCheckbox(data, type, row, meta) {
1703
+ var fn = function (data, type, row, meta) {
1559
1704
  var dtRow = meta.settings.aoData[meta.row];
1560
1705
  var selected = dtRow._select_selected;
1561
1706
  var ariaLabel = meta.settings.oLanguage.select.aria.rowCheckbox;
1707
+ var selectable = meta.settings._select.selectable;
1562
1708
 
1563
1709
  if (type === 'display') {
1710
+ // Check if the row is selectable before showing the checkbox
1711
+ if (selectable) {
1712
+ var result = selectable(row, dtRow.nTr, meta.row);
1713
+
1714
+ if (result === false) {
1715
+ return '';
1716
+ }
1717
+ }
1718
+
1564
1719
  return $('<input>')
1565
1720
  .attr({
1566
1721
  'aria-label': ariaLabel,
@@ -1589,6 +1744,12 @@ DataTable.render.select = function (valueProp, nameProp) {
1589
1744
 
1590
1745
  return selected ? 'X' : '';
1591
1746
  }
1747
+
1748
+ // Workaround so uglify doesn't strip the function name. It is used
1749
+ // for the column type detection.
1750
+ fn._name = 'selectCheckbox';
1751
+
1752
+ return fn;
1592
1753
  }
1593
1754
 
1594
1755
  // Legacy checkbox ordering
@@ -1613,11 +1774,10 @@ $.fn.DataTable.select = DataTable.select;
1613
1774
  * Initialisation
1614
1775
  */
1615
1776
 
1616
- // DataTables creation - check if select has been defined in the options. Note
1617
- // this required that the table be in the document! If it isn't then something
1618
- // needs to trigger this method unfortunately. The next major release of
1619
- // DataTables will rework the events and address this.
1620
- $(document).on('preInit.dt.dtSelect', function (e, ctx) {
1777
+ // DataTables creation - we need this to run _before_ data is read in, but
1778
+ // for backwards compat. we also run again on preInit. If it happens twice
1779
+ // it will simply do nothing the second time around.
1780
+ $(document).on('i18n.dt.dtSelect preInit.dt.dtSelect', function (e, ctx) {
1621
1781
  if (e.namespace !== 'dt') {
1622
1782
  return;
1623
1783
  }
@@ -1,4 +1,4 @@
1
- /*! Select for DataTables 2.0.4
1
+ /*! Select for DataTables 2.1.0
2
2
  * © SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
- !function(l){var s,c;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return l(e,window,document)}):"object"==typeof exports?(s=require("jquery"),c=function(e,t){t.fn.dataTable||require("datatables.net")(e,t)},"undefined"==typeof window?module.exports=function(e,t){return e=e||window,t=t||s(e),c(e,t),l(t,e,e.document)}:(c(window,s),module.exports=l(s,window,window.document))):l(jQuery,window,document)}(function(m,i,e){"use strict";var p=m.fn.dataTable;function r(n,e,t){function l(t,l){l<t&&(e=l,l=t,t=e);var e,s=!1;return n.columns(":visible").indexes().filter(function(e){return e===t&&(s=!0),e===l?!(s=!1):s})}function s(t,l){var e,s=n.rows({search:"applied"}).indexes(),c=(s.indexOf(t)>s.indexOf(l)&&(e=l,l=t,t=e),!1);return s.filter(function(e){return e===t&&(c=!0),e===l?!(c=!1):c})}var c,t=n.cells({selected:!0}).any()||t?(c=l(t.column,e.column),s(t.row,e.row)):(c=l(0,e.column),s(0,e.row)),t=n.cells(t,c).flatten();n.cells(e,{selected:!0}).any()?n.cells(t).deselect():n.cells(t).select()}function u(e){var t=p.select.classes.checkbox;return e?t.replace(/ /g,"."):t}function s(e){var t=e.settings()[0]._select.selector;m(e.table().container()).off("mousedown.dtSelect",t).off("mouseup.dtSelect",t).off("click.dtSelect",t),m("body").off("click.dtSelect"+w(e.table().node()))}function n(o){var a,t=m(o.table().container()),l=o.settings()[0],s=l._select.selector;t.on("mousedown.dtSelect",s,function(e){(e.shiftKey||e.metaKey||e.ctrlKey)&&t.css("-moz-user-select","none").one("selectstart.dtSelect",s,function(){return!1}),i.getSelection&&(a=i.getSelection())}).on("mouseup.dtSelect",s,function(){t.css("-moz-user-select","")}).on("click.dtSelect",s,function(e){var t,l=o.select.items();if(a){var s=i.getSelection();if((!s.anchorNode||m(s.anchorNode).closest("table")[0]===o.table().node())&&s!==a)return}var c,s=o.settings()[0],n=o.table().container();m(e.target).closest("div.dt-container")[0]==n&&(n=o.cell(m(e.target).closest("td, th"))).any()&&(c=m.Event("user-select.dt"),d(o,c,[l,n,e]),c.isDefaultPrevented()||(c=n.index(),"row"===l?(t=c.row,v(e,o,s,"row",t)):"column"===l?(t=n.index().column,v(e,o,s,"column",t)):"cell"===l&&(t=n.index(),v(e,o,s,"cell",t)),s._select_lastCell=c))}),m("body").on("click.dtSelect"+w(o.table().node()),function(e){var t;!l._select.blurable||m(e.target).parents().filter(o.table().container()).length||0===m(e.target).parents("html").length||m(e.target).parents("div.DTE").length||(t=m.Event("select-blur.dt"),d(o,t,[e.target,e]),t.isDefaultPrevented())||h(l,!0)})}function d(e,t,l,s){s&&!e.flatten().length||("string"==typeof t&&(t+=".dt"),l.unshift(e),m(e.table().node()).trigger(t,l))}function a(s,e){var t,l,c,n,o;"api"!==s.select.style()&&!1!==s.select.info()&&(o=s.rows({selected:!0}).flatten().length,t=s.columns({selected:!0}).flatten().length,l=s.cells({selected:!0}).flatten().length,c=function(e,t,l){e.append(m('<span class="select-item"/>').append(s.i18n("select."+t+"s",{_:"%d "+t+"s selected",0:"",1:"1 "+t+" selected"},l)))},e=m(e),c(n=m('<span class="select-info"/>'),"row",o),c(n,"column",t),c(n,"cell",l),(o=e.children("span.select-info")).length&&o.remove(),""!==n.text())&&e.append(n)}function _(o,a){o.columns(".dt-select").every(function(){var n,e=this.header();m("input",e).length||(n=m("<input>").attr({class:u(!0),type:"checkbox","aria-label":o.i18n("select.aria.headerCheckbox")||"Select all rows"}).appendTo(e).on("change",function(){this.checked?("select-page"==a?o.rows({page:"current"}):o.rows({search:"applied"})).select():o.rows({selected:!0}).deselect()}).on("click",function(e){e.stopPropagation()}),o.on("draw select deselect",function(e,t,l){var s,c;"row"!==l&&l||(l=o.rows({selected:!0}).count(),s=o.rows({search:"applied",selected:!0}).count(),c=("select-page"==a?o.rows({page:"current"}):o.rows({search:"applied"})).count(),s&&s<=l&&s===c?n.prop("checked",!0).prop("indeterminate",!1):0===s&&0===l?n.prop("checked",!1).prop("indeterminate",!1):n.prop("checked",!1).prop("indeterminate",!0))}))})}function f(e,t,l,s){var c,n=e[t+"s"]({search:"applied"}).indexes(),s=n.indexOf(s),o=n.indexOf(l);e[t+"s"]({selected:!0}).any()||-1!==s?(o<s&&(c=o,o=s,s=c),n.splice(o+1,n.length),n.splice(0,s)):n.splice(n.indexOf(l)+1,n.length),e[t](l,{selected:!0}).any()?(n.splice(n.indexOf(l),1),e[t+"s"](n).deselect()):e[t+"s"](n).select()}function h(e,t){!t&&"single"!==e._select.style||((t=new p.Api(e)).rows({selected:!0}).deselect(),t.columns({selected:!0}).deselect(),t.cells({selected:!0}).deselect())}function v(e,t,l,s,c){var n=t.select.style(),o=t.select.toggleable(),a=t[s](c,{selected:!0}).any();a&&!o||("os"===n?e.ctrlKey||e.metaKey?t[s](c).select(!a):e.shiftKey?"cell"===s?r(t,c,l._select_lastCell||null):f(t,s,c,l._select_lastCell?l._select_lastCell[s]:null):(o=t[s+"s"]({selected:!0}),a&&1===o.flatten().length?t[s](c).deselect():(o.deselect(),t[s](c).select())):"multi+shift"==n&&e.shiftKey?"cell"===s?r(t,c,l._select_lastCell||null):f(t,s,c,l._select_lastCell?l._select_lastCell[s]:null):t[s](c).select(!a))}function w(e){return e.id.replace(/[^a-zA-Z0-9\-\_]/g,"-")}p.select={},p.select.classes={checkbox:"dt-select-checkbox"},p.select.version="2.0.4",p.select.init=function(c){var e,t,l,s,n,o,a,i,r,u,d,f,h=c.settings()[0];if(!p.versionCheck("2"))throw"Warning: Select requires DataTables 2 or newer";!h._select&&(e=c.state.loaded(),t=function(e,t,l){if(null!==l&&void 0!==l.select){if(c.rows({selected:!0}).any()&&c.rows().deselect(),void 0!==l.select.rows&&c.rows(l.select.rows).select(),c.columns({selected:!0}).any()&&c.columns().deselect(),void 0!==l.select.columns&&c.columns(l.select.columns).select(),c.cells({selected:!0}).any()&&c.cells().deselect(),void 0!==l.select.cells)for(var s=0;s<l.select.cells.length;s++)c.cell(l.select.cells[s].row,l.select.cells[s].column).select();c.state.save()}},c.on("stateSaveParams",function(e,t,l){l.select={},l.select.rows=c.rows({selected:!0}).ids(!0).toArray(),l.select.columns=c.columns({selected:!0})[0],l.select.cells=c.cells({selected:!0})[0].map(function(e){return{row:c.row(e.row).id(!0),column:e.column}})}).on("stateLoadParams",t).one("init",function(){t(0,0,e)}),s=h.oInit.select,l=p.defaults.select,l=void 0===s?l:s,s="row",r="td, th",u="selected",f=!(d=i=a=!(o=!(n="api"))),h._select={infoEls:[]},!0===l?(n="os",f=!0):"string"==typeof l?(n=l,f=!0):m.isPlainObject(l)&&(void 0!==l.blurable&&(o=l.blurable),void 0!==l.toggleable&&(a=l.toggleable),void 0!==l.info&&(i=l.info),void 0!==l.items&&(s=l.items),f=(n=void 0!==l.style?l.style:"os",!0),void 0!==l.selector&&(r=l.selector),void 0!==l.className&&(u=l.className),void 0!==l.headerCheckbox)&&(d=l.headerCheckbox),c.select.selector(r),c.select.items(s),c.select.style(n),c.select.blurable(o),c.select.toggleable(a),c.select.info(i),h._select.className=u,!f&&m(c.table().node()).hasClass("selectable")&&c.select.style("os"),d||"select-page"===d||"select-all"===d)&&(_(c,d),c.on("init",function(){_(c,d)}))},m.each([{type:"row",prop:"aoData"},{type:"column",prop:"aoColumns"}],function(e,i){p.ext.selector[i.type].push(function(e,t,l){var s,c=t.selected,n=[];if(!0!==c&&!1!==c)return l;for(var o=0,a=l.length;o<a;o++)(s=e[i.prop][l[o]])&&(!0===c&&!0===s._select_selected||!1===c&&!s._select_selected)&&n.push(l[o]);return n})}),p.ext.selector.cell.push(function(e,t,l){var s,c=t.selected,n=[];if(void 0===c)return l;for(var o=0,a=l.length;o<a;o++)(s=e.aoData[l[o].row])&&(!0===c&&s._selected_cells&&!0===s._selected_cells[l[o].column]||!1===c&&(!s._selected_cells||!s._selected_cells[l[o].column]))&&n.push(l[o]);return n});var t=p.Api.register,l=p.Api.registerPlural;function o(t,l){return function(e){return e.i18n("buttons."+t,l)}}function b(e){e=e._eventNamespace;return"draw.dt.DT"+e+" select.dt.DT"+e+" deselect.dt.DT"+e}t("select()",function(){return this.iterator("table",function(e){p.select.init(new p.Api(e))})}),t("select.blurable()",function(t){return void 0===t?this.context[0]._select.blurable:this.iterator("table",function(e){e._select.blurable=t})}),t("select.toggleable()",function(t){return void 0===t?this.context[0]._select.toggleable:this.iterator("table",function(e){e._select.toggleable=t})}),t("select.info()",function(t){return void 0===t?this.context[0]._select.info:this.iterator("table",function(e){e._select.info=t})}),t("select.items()",function(t){return void 0===t?this.context[0]._select.items:this.iterator("table",function(e){e._select.items=t,d(new p.Api(e),"selectItems",[t])})}),t("select.style()",function(l){return void 0===l?this.context[0]._select.style:this.iterator("table",function(e){e._select||p.select.init(new p.Api(e)),e._select_init||(o=e,c=new p.Api(o),o._select_init=!0,o.aoRowCreatedCallback.push(function(e,t,l){var s,c,n=o.aoData[l];for(n._select_selected&&m(e).addClass(o._select.className).find("input."+u(!0)).prop("checked",!0),s=0,c=o.aoColumns.length;s<c;s++)(o.aoColumns[s]._select_selected||n._selected_cells&&n._selected_cells[s])&&m(n.anCells[s]).addClass(o._select.className)}),c.on("preXhr.dt.dtSelect",function(e,t){var l,s;t===c.settings()[0]&&(l=c.rows({selected:!0}).ids(!0).filter(function(e){return void 0!==e}),s=c.cells({selected:!0}).eq(0).map(function(e){var t=c.row(e.row).id(!0);return t?{row:t,column:e.column}:void 0}).filter(function(e){return void 0!==e}),c.one("draw.dt.dtSelect",function(){c.rows(l).select(),s.any()&&s.each(function(e){c.cells(e.row,e.column).select()})}))}),c.on("info.dt",function(e,t,l){t._select.infoEls.includes(l)||t._select.infoEls.push(l),a(c,l)}),c.on("select.dtSelect.dt deselect.dtSelect.dt",function(){o._select.infoEls.forEach(function(e){a(c,e)}),c.state.save()}),c.on("destroy.dtSelect",function(){m(c.rows({selected:!0}).nodes()).removeClass(c.settings()[0]._select.className),m("input."+u(!0),c.table().header()).remove(),s(c),c.off(".dtSelect"),m("body").off(".dtSelect"+w(c.table().node()))})),e._select.style=l;var o,c,t=new p.Api(e);s(t),"api"!==l&&n(t),d(new p.Api(e),"selectStyle",[l])})}),t("select.selector()",function(t){return void 0===t?this.context[0]._select.selector:this.iterator("table",function(e){s(new p.Api(e)),e._select.selector=t,"api"!==e._select.style&&n(new p.Api(e))})}),t("select.last()",function(e){var t=this.context[0];return e?(t._select_lastCell=e,this):t._select_lastCell}),l("rows().select()","row().select()",function(e){var o=this;return!1===e?this.deselect():(this.iterator("row",function(e,t){h(e);var l=e.aoData[t],s=e.aoColumns;m(l.nTr).addClass(e._select.className),l._select_selected=!0;for(var c=0;c<s.length;c++){var n=s[c];null===n.sType&&o.columns().types(),"select-checkbox"===n.sType&&((n=l.anCells)&&n[c]&&m("input."+u(!0),n[c]).prop("checked",!0),null!==l._aSortData)&&(l._aSortData[c]=null)}}),this.iterator("table",function(e,t){d(o,"select",["row",o[t]],!0)}),this)}),t("row().selected()",function(){var e=this.context[0];return!!(e&&this.length&&e.aoData[this[0]]&&e.aoData[this[0]]._select_selected)}),l("columns().select()","column().select()",function(e){var l=this;return!1===e?this.deselect():(this.iterator("column",function(e,t){h(e),e.aoColumns[t]._select_selected=!0;t=new p.Api(e).column(t);m(t.header()).addClass(e._select.className),m(t.footer()).addClass(e._select.className),t.nodes().to$().addClass(e._select.className)}),this.iterator("table",function(e,t){d(l,"select",["column",l[t]],!0)}),this)}),t("column().selected()",function(){var e=this.context[0];return!!(e&&this.length&&e.aoColumns[this[0]]&&e.aoColumns[this[0]]._select_selected)}),l("cells().select()","cell().select()",function(e){var l=this;return!1===e?this.deselect():(this.iterator("cell",function(e,t,l){h(e);t=e.aoData[t];void 0===t._selected_cells&&(t._selected_cells=[]),t._selected_cells[l]=!0,t.anCells&&m(t.anCells[l]).addClass(e._select.className)}),this.iterator("table",function(e,t){d(l,"select",["cell",l.cells(l[t]).indexes().toArray()],!0)}),this)}),t("cell().selected()",function(){var e=this.context[0];if(e&&this.length){e=e.aoData[this[0][0].row];if(e&&e._selected_cells&&e._selected_cells[this[0][0].column])return!0}return!1}),l("rows().deselect()","row().deselect()",function(){var o=this;return this.iterator("row",function(e,t){var l=e.aoData[t],s=e.aoColumns;m(l.nTr).removeClass(e._select.className),l._select_selected=!1,e._select_lastCell=null;for(var c=0;c<s.length;c++){var n=s[c];null===n.sType&&o.columns().types(),"select-checkbox"===n.sType&&((n=l.anCells)&&n[c]&&m("input."+u(!0),l.anCells[c]).prop("checked",!1),null!==l._aSortData)&&(l._aSortData[c]=null)}}),this.iterator("table",function(e,t){d(o,"deselect",["row",o[t]],!0)}),this}),l("columns().deselect()","column().deselect()",function(){var l=this;return this.iterator("column",function(s,e){s.aoColumns[e]._select_selected=!1;var t=new p.Api(s),l=t.column(e);m(l.header()).removeClass(s._select.className),m(l.footer()).removeClass(s._select.className),t.cells(null,e).indexes().each(function(e){var t=s.aoData[e.row],l=t._selected_cells;!t.anCells||l&&l[e.column]||m(t.anCells[e.column]).removeClass(s._select.className)})}),this.iterator("table",function(e,t){d(l,"deselect",["column",l[t]],!0)}),this}),l("cells().deselect()","cell().deselect()",function(){var l=this;return this.iterator("cell",function(e,t,l){t=e.aoData[t];void 0!==t._selected_cells&&(t._selected_cells[l]=!1),t.anCells&&!e.aoColumns[l]._select_selected&&m(t.anCells[l]).removeClass(e._select.className)}),this.iterator("table",function(e,t){d(l,"deselect",["cell",l[t]],!0)}),this});var g=0;return m.extend(p.ext.buttons,{selected:{text:o("selected","Selected"),className:"buttons-selected",limitTo:["rows","columns","cells"],init:function(l,e,s){var c=this;s._eventNamespace=".select"+g++,l.on(b(s),function(){var e,t;c.enable((e=l,!(-1===(t=s).limitTo.indexOf("rows")||!e.rows({selected:!0}).any())||!(-1===t.limitTo.indexOf("columns")||!e.columns({selected:!0}).any())||!(-1===t.limitTo.indexOf("cells")||!e.cells({selected:!0}).any())))}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},selectedSingle:{text:o("selectedSingle","Selected single"),className:"buttons-selected-single",init:function(t,e,l){var s=this;l._eventNamespace=".select"+g++,t.on(b(l),function(){var e=t.rows({selected:!0}).flatten().length+t.columns({selected:!0}).flatten().length+t.cells({selected:!0}).flatten().length;s.enable(1===e)}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},selectAll:{text:o("selectAll","Select all"),className:"buttons-select-all",action:function(e,t,l,s){var c=this.select.items(),n=s.selectorModifier;(n?("function"==typeof n&&(n=n.call(t,e,t,l,s)),this[c+"s"](n)):this[c+"s"]()).select()}},selectNone:{text:o("selectNone","Deselect all"),className:"buttons-select-none",action:function(){h(this.settings()[0],!0)},init:function(t,e,l){var s=this;l._eventNamespace=".select"+g++,t.on(b(l),function(){var e=t.rows({selected:!0}).flatten().length+t.columns({selected:!0}).flatten().length+t.cells({selected:!0}).flatten().length;s.enable(0<e)}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},showSelected:{text:o("showSelected","Show only selected"),className:"buttons-show-selected",action:function(e,t){var s;t.search.fixed("dt-select")?(t.search.fixed("dt-select",null),this.active(!1)):(s=t.settings()[0].aoData,t.search.fixed("dt-select",function(e,t,l){return s[l]._select_selected}),this.active(!0)),t.draw()}}}),m.each(["Row","Column","Cell"],function(e,t){var c=t.toLowerCase();p.ext.buttons["select"+t+"s"]={text:o("select"+t+"s","Select "+c+"s"),className:"buttons-select-"+c+"s",action:function(){this.select.items(c)},init:function(e){var s=this;e.on("selectItems.dt.DT",function(e,t,l){s.active(l===c)})}}}),p.type("select-checkbox",{className:"dt-select",detect:p.versionCheck("2.1")?{oneOf:function(){return!1},allOf:function(){return!1},init:function(e,t,l){return t.mRender&&"selectCheckbox"===t.mRender.name}}:function(e){return"select-checkbox"===e&&e},order:{pre:function(e){return"X"===e?-1:0}}}),m.extend(!0,p.defaults.oLanguage,{select:{aria:{rowCheckbox:"Select row"}}}),p.render.select=function(e,t){var n=e?p.util.get(e):null,o=t?p.util.get(t):null;return function(e,t,l,s){var c=s.settings.aoData[s.row]._select_selected,s=s.settings.oLanguage.select.aria.rowCheckbox;return"display"===t?m("<input>").attr({"aria-label":s,class:u(),name:o?o(l):null,type:"checkbox",value:n?n(l):null,checked:c}).on("input",function(e){e.preventDefault(),this.checked=m(this).closest("tr").hasClass("selected")})[0]:"type"===t?"select-checkbox":"filter"!==t&&c?"X":""}},p.ext.order["select-checkbox"]=function(t,e){return this.api().column(e,{order:"index"}).nodes().map(function(e){return"row"===t._select.items?m(e).parent().hasClass(t._select.className).toString():"cell"===t._select.items&&m(e).hasClass(t._select.className).toString()})},m.fn.DataTable.select=p.select,m(e).on("preInit.dt.dtSelect",function(e,t){"dt"===e.namespace&&p.select.init(new p.Api(t))}),p});
4
+ !function(l){var s,c;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return l(e,window,document)}):"object"==typeof exports?(s=require("jquery"),c=function(e,t){t.fn.dataTable||require("datatables.net")(e,t)},"undefined"==typeof window?module.exports=function(e,t){return e=e||window,t=t||s(e),c(e,t),l(t,e,e.document)}:(c(window,s),module.exports=l(s,window,window.document))):l(jQuery,window,document)}(function(m,i,e){"use strict";var p=m.fn.dataTable;function r(n,e,t){function l(t,l){l<t&&(e=l,l=t,t=e);var e,s=!1;return n.columns(":visible").indexes().filter(function(e){return e===t&&(s=!0),e===l?!(s=!1):s})}function s(t,l){var e,s=n.rows({search:"applied"}).indexes(),c=(s.indexOf(t)>s.indexOf(l)&&(e=l,l=t,t=e),!1);return s.filter(function(e){return e===t&&(c=!0),e===l?!(c=!1):c})}var c,t=n.cells({selected:!0}).any()||t?(c=l(t.column,e.column),s(t.row,e.row)):(c=l(0,e.column),s(0,e.row)),t=n.cells(t,c).flatten();n.cells(e,{selected:!0}).any()?n.cells(t).deselect():n.cells(t).select()}function v(e){var t=p.select.classes.checkbox;return e?t.replace(/ /g,"."):t}function c(e){var t=e.settings()[0]._select.selector;m(e.table().container()).off("mousedown.dtSelect",t).off("mouseup.dtSelect",t).off("click.dtSelect",t),m("body").off("click.dtSelect"+_(e.table().node()))}function n(o){var a,t=m(o.table().container()),l=o.settings()[0],s=l._select.selector;t.on("mousedown.dtSelect",s,function(e){(e.shiftKey||e.metaKey||e.ctrlKey)&&t.css("-moz-user-select","none").one("selectstart.dtSelect",s,function(){return!1}),i.getSelection&&(a=i.getSelection())}).on("mouseup.dtSelect",s,function(){t.css("-moz-user-select","")}).on("click.dtSelect",s,function(e){var t,l=o.select.items();if(a){var s=i.getSelection();if((!s.anchorNode||m(s.anchorNode).closest("table")[0]===o.table().node())&&s!==a)return}var c,s=o.settings()[0],n=o.table().container();m(e.target).closest("div.dt-container")[0]==n&&(n=o.cell(m(e.target).closest("td, th"))).any()&&(c=m.Event("user-select.dt"),u(o,c,[l,n,e]),c.isDefaultPrevented()||(c=n.index(),"row"===l?(t=c.row,h(e,o,s,"row",t)):"column"===l?(t=n.index().column,h(e,o,s,"column",t)):"cell"===l&&(t=n.index(),h(e,o,s,"cell",t)),s._select_lastCell=c))}),m("body").on("click.dtSelect"+_(o.table().node()),function(e){var t;!l._select.blurable||m(e.target).parents().filter(o.table().container()).length||0===m(e.target).parents("html").length||m(e.target).parents("div.DTE").length||(t=m.Event("select-blur.dt"),u(o,t,[e.target,e]),t.isDefaultPrevented())||f(l,!0)})}function u(e,t,l,s){s&&!e.flatten().length||("string"==typeof t&&(t+=".dt"),l.unshift(e),m(e.table().node()).trigger(t,l))}function b(e){return e.mRender&&"selectCheckbox"===e.mRender._name}function s(s,e){var t,l,c,n,o;"api"!==s.select.style()&&!1!==s.select.info()&&(o=s.settings()[0]._select_set.length||s.rows({selected:!0}).count(),t=s.columns({selected:!0}).count(),l=s.cells({selected:!0}).count(),c=function(e,t,l){e.append(m('<span class="select-item"/>').append(s.i18n("select."+t+"s",{_:"%d "+t+"s selected",0:"",1:"1 "+t+" selected"},l)))},e=m(e),c(n=m('<span class="select-info"/>'),"row",o),c(n,"column",t),c(n,"cell",l),(o=e.children("span.select-info")).length&&o.remove(),""!==n.text())&&e.append(n)}function o(o){var r,a=new p.Api(o);o._select_init=!0,o._select_set=[],o.aoRowCreatedCallback.push(function(e,t,l){var s,c,n=o.aoData[l],l=a.row(l).id();for((n._select_selected||"undefined"!==l&&o._select_set.includes(l))&&(n._select_selected=!0,m(e).addClass(o._select.className).find("input."+v(!0)).prop("checked",!0)),s=0,c=o.aoColumns.length;s<c;s++)(o.aoColumns[s]._select_selected||n._selected_cells&&n._selected_cells[s])&&m(n.anCells[s]).addClass(o._select.className)}),(r=a).on("select",function(e,t,l,s){if("row"===l)for(var l=r.settings()[0],c=r,n=l._select_set,o=s,a=0;a<o.length;a++){var i=c.row(o[a]).id();i&&"undefined"!==i&&!n.includes(i)&&n.push(i)}}),r.on("deselect",function(e,t,l,s){if("row"===l)for(var l=r.settings()[0],c=r,n=l._select_set,o=s,a=0;a<o.length;a++){var i=c.row(o[a]).id(),i=n.indexOf(i);-1!==i&&n.splice(i,1)}}),a.on("info.dt",function(e,t,l){t._select.infoEls.includes(l)||t._select.infoEls.push(l),s(a,l)}),a.on("select.dtSelect.dt deselect.dtSelect.dt",function(){o._select.infoEls.forEach(function(e){s(a,e)}),a.state.save()}),a.on("destroy.dtSelect",function(){m(a.rows({selected:!0}).nodes()).removeClass(a.settings()[0]._select.className),m("input."+v(!0),a.table().header()).remove(),c(a),a.off(".dtSelect"),m("body").off(".dtSelect"+_(a.table().node()))})}function d(e,t,l,s){var c,n=e[t+"s"]({search:"applied"}).indexes(),s=n.indexOf(s),o=n.indexOf(l);e[t+"s"]({selected:!0}).any()||-1!==s?(o<s&&(c=o,o=s,s=c),n.splice(o+1,n.length),n.splice(0,s)):n.splice(n.indexOf(l)+1,n.length),e[t](l,{selected:!0}).any()?(n.splice(n.indexOf(l),1),e[t+"s"](n).deselect()):e[t+"s"](n).select()}function f(e,t){!t&&"single"!==e._select.style||((t=new p.Api(e)).rows({selected:!0}).deselect(),t.columns({selected:!0}).deselect(),t.cells({selected:!0}).deselect())}function h(e,t,l,s,c){var n=t.select.style(),o=t.select.toggleable(),a=t[s](c,{selected:!0}).any();a&&!o||("os"===n?e.ctrlKey||e.metaKey?t[s](c).select(!a):e.shiftKey?"cell"===s?r(t,c,l._select_lastCell||null):d(t,s,c,l._select_lastCell?l._select_lastCell[s]:null):(o=t[s+"s"]({selected:!0}),a&&1===o.flatten().length?t[s](c).deselect():(o.deselect(),t[s](c).select())):"multi+shift"==n&&e.shiftKey?"cell"===s?r(t,c,l._select_lastCell||null):d(t,s,c,l._select_lastCell?l._select_lastCell[s]:null):t[s](c).select(!a))}function _(e){return e.id.replace(/[^a-zA-Z0-9\-\_]/g,"-")}p.select={},p.select.classes={checkbox:"dt-select-checkbox"},p.select.version="2.1.0",p.select.init=function(o){var e,t,l,s,c,n,a,i,r,u,d,f,h,_=o.settings()[0];if(!p.versionCheck("2"))throw"Warning: Select requires DataTables 2 or newer";!_._select&&(e=o.state.loaded(),t=function(e,t,l){if(null!==l&&void 0!==l.select){if(o.rows({selected:!0}).any()&&o.rows().deselect(),void 0!==l.select.rows&&o.rows(l.select.rows).select(),o.columns({selected:!0}).any()&&o.columns().deselect(),void 0!==l.select.columns&&o.columns(l.select.columns).select(),o.cells({selected:!0}).any()&&o.cells().deselect(),void 0!==l.select.cells)for(var s=0;s<l.select.cells.length;s++)o.cell(l.select.cells[s].row,l.select.cells[s].column).select();o.state.save()}},o.on("stateSaveParams",function(e,t,l){l.select={},l.select.rows=o.rows({selected:!0}).ids(!0).toArray(),l.select.columns=o.columns({selected:!0})[0],l.select.cells=o.cells({selected:!0})[0].map(function(e){return{row:o.row(e.row).id(!0),column:e.column}})}).on("stateLoadParams",t).one("init",function(){t(0,0,e)}),s=_.oInit.select,l=p.defaults.select,l=void 0===s?l:s,s="row",a=!(n=!(c="api")),u="td, th",d="selected",h=!(f=r=!(i=null)),_._select={infoEls:[]},!0===l?(c="os",h=!0):"string"==typeof l?(c=l,h=!0):m.isPlainObject(l)&&(void 0!==l.blurable&&(n=l.blurable),void 0!==l.toggleable&&(a=l.toggleable),void 0!==l.info&&(r=l.info),void 0!==l.items&&(s=l.items),h=(c=void 0!==l.style?l.style:"os",!0),void 0!==l.selector&&(u=l.selector),void 0!==l.className&&(d=l.className),void 0!==l.headerCheckbox&&(f=l.headerCheckbox),void 0!==l.selectable)&&(i=l.selectable),o.select.selector(u),o.select.items(s),o.select.style(c),o.select.blurable(n),o.select.toggleable(a),o.select.info(r),o.select.selectable(i),_._select.className=d,!h&&m(o.table().node()).hasClass("selectable")&&o.select.style("os"),f||"select-page"===f||"select-all"===f)&&o.ready(function(){var c,n,l;n=f,l=(c=o).settings()[0].aoColumns,c.columns().iterator("column",function(e,t){var s;b(l[t])&&(t=c.column(t).header(),m("input",t).length||(s=m("<input>").attr({class:v(!0),type:"checkbox","aria-label":c.i18n("select.aria.headerCheckbox")||"Select all rows"}).appendTo(t).on("change",function(){this.checked?("select-page"==n?c.rows({page:"current"}):c.rows({search:"applied"})).select():("select-page"==n?c.rows({page:"current",selected:!0}):c.rows({selected:!0})).deselect()}).on("click",function(e){e.stopPropagation()}),c.on("draw select deselect",function(e,t,l){"row"!==l&&l||((l=function(e,t){var l=e.settings()[0],s=l._select.selectable,c=0,n=("select-page"==t?e.rows({page:"current",selected:!0}):e.rows({selected:!0})).count(),o=("select-page"==t?e.rows({page:"current",selected:!0}):e.rows({search:"applied",selected:!0})).count();if(s)for(var a=("select-page"==t?e.rows({page:"current"}):e.rows({search:"applied"})).indexes(),i=0;i<a.length;i++){var r=l.aoData[a[i]];s(r._aData,r.nTr,a[i])&&c++}else c=("select-page"==t?e.rows({page:"current"}):e.rows({search:"applied"})).count();return{available:c,count:n,search:o}}(c,n)).search&&l.search<=l.count&&l.search===l.available?s.prop("checked",!0).prop("indeterminate",!1):0===l.search&&0===l.count?s.prop("checked",!1).prop("indeterminate",!1):s.prop("checked",!1).prop("indeterminate",!0))})))})})},m.each([{type:"row",prop:"aoData"},{type:"column",prop:"aoColumns"}],function(e,i){p.ext.selector[i.type].push(function(e,t,l){var s,c=t.selected,n=[];if(!0!==c&&!1!==c)return l;for(var o=0,a=l.length;o<a;o++)(s=e[i.prop][l[o]])&&(!0===c&&!0===s._select_selected||!1===c&&!s._select_selected)&&n.push(l[o]);return n})}),p.ext.selector.cell.push(function(e,t,l){var s,c=t.selected,n=[];if(void 0===c)return l;for(var o=0,a=l.length;o<a;o++)(s=e.aoData[l[o].row])&&(!0===c&&s._selected_cells&&!0===s._selected_cells[l[o].column]||!1===c&&(!s._selected_cells||!s._selected_cells[l[o].column]))&&n.push(l[o]);return n});var t=p.Api.register,l=p.Api.registerPlural;function a(t,l){return function(e){return e.i18n("buttons."+t,l)}}function w(e){e=e._eventNamespace;return"draw.dt.DT"+e+" select.dt.DT"+e+" deselect.dt.DT"+e}t("select()",function(){return this.iterator("table",function(e){p.select.init(new p.Api(e))})}),t("select.blurable()",function(t){return void 0===t?this.context[0]._select.blurable:this.iterator("table",function(e){e._select.blurable=t})}),t("select.toggleable()",function(t){return void 0===t?this.context[0]._select.toggleable:this.iterator("table",function(e){e._select.toggleable=t})}),t("select.info()",function(t){return void 0===t?this.context[0]._select.info:this.iterator("table",function(e){e._select.info=t})}),t("select.items()",function(t){return void 0===t?this.context[0]._select.items:this.iterator("table",function(e){e._select.items=t,u(new p.Api(e),"selectItems",[t])})}),t("select.style()",function(l){return void 0===l?this.context[0]._select.style:this.iterator("table",function(e){e._select||p.select.init(new p.Api(e)),e._select_init||o(e),e._select.style=l;var t=new p.Api(e);"api"!==l?t.ready(function(){c(t),n(t)}):c(t),u(new p.Api(e),"selectStyle",[l])})}),t("select.selector()",function(s){return void 0===s?this.context[0]._select.selector:this.iterator("table",function(e){var t=new p.Api(e),l=e._select.style;c(t),e._select.selector=s,l&&"api"!==l?t.ready(function(){c(t),n(t)}):c(t)})}),t("select.selectable()",function(e){var t=this.context[0];return e?(t._select.selectable=e,this):t._select.selectable}),t("select.last()",function(e){var t=this.context[0];return e?(t._select_lastCell=e,this):t._select_lastCell}),t("select.cumulative()",function(){var e=this.context[0];return e&&e._select_set?e._select_set:[]}),l("rows().select()","row().select()",function(e){var o=this,a=[];return!1===e?this.deselect():(this.iterator("row",function(e,t){f(e);var l=e.aoData[t],s=e.aoColumns;if(e._select.selectable&&!1===e._select.selectable(l._aData,l.nTr,t))return;m(l.nTr).addClass(e._select.className),l._select_selected=!0,a.push(t);for(var c=0;c<s.length;c++){var n=s[c];null===n.sType&&o.columns().types(),b(n)&&((n=l.anCells)&&n[c]&&m("input."+v(!0),n[c]).prop("checked",!0),null!==l._aSortData)&&(l._aSortData[c]=null)}}),this.iterator("table",function(e){u(o,"select",["row",a],!0)}),this)}),t("row().selected()",function(){var e=this.context[0];return!!(e&&this.length&&e.aoData[this[0]]&&e.aoData[this[0]]._select_selected)}),l("columns().select()","column().select()",function(e){var l=this;return!1===e?this.deselect():(this.iterator("column",function(e,t){f(e),e.aoColumns[t]._select_selected=!0;t=new p.Api(e).column(t);m(t.header()).addClass(e._select.className),m(t.footer()).addClass(e._select.className),t.nodes().to$().addClass(e._select.className)}),this.iterator("table",function(e,t){u(l,"select",["column",l[t]],!0)}),this)}),t("column().selected()",function(){var e=this.context[0];return!!(e&&this.length&&e.aoColumns[this[0]]&&e.aoColumns[this[0]]._select_selected)}),l("cells().select()","cell().select()",function(e){var l=this;return!1===e?this.deselect():(this.iterator("cell",function(e,t,l){f(e);t=e.aoData[t];void 0===t._selected_cells&&(t._selected_cells=[]),t._selected_cells[l]=!0,t.anCells&&m(t.anCells[l]).addClass(e._select.className)}),this.iterator("table",function(e,t){u(l,"select",["cell",l.cells(l[t]).indexes().toArray()],!0)}),this)}),t("cell().selected()",function(){var e=this.context[0];if(e&&this.length){e=e.aoData[this[0][0].row];if(e&&e._selected_cells&&e._selected_cells[this[0][0].column])return!0}return!1}),l("rows().deselect()","row().deselect()",function(){var o=this;return this.iterator("row",function(e,t){var l=e.aoData[t],s=e.aoColumns;m(l.nTr).removeClass(e._select.className),l._select_selected=!1,e._select_lastCell=null;for(var c=0;c<s.length;c++){var n=s[c];null===n.sType&&o.columns().types(),b(n)&&((n=l.anCells)&&n[c]&&m("input."+v(!0),l.anCells[c]).prop("checked",!1),null!==l._aSortData)&&(l._aSortData[c]=null)}}),this.iterator("table",function(e,t){u(o,"deselect",["row",o[t]],!0)}),this}),l("columns().deselect()","column().deselect()",function(){var l=this;return this.iterator("column",function(s,e){s.aoColumns[e]._select_selected=!1;var t=new p.Api(s),l=t.column(e);m(l.header()).removeClass(s._select.className),m(l.footer()).removeClass(s._select.className),t.cells(null,e).indexes().each(function(e){var t=s.aoData[e.row],l=t._selected_cells;!t.anCells||l&&l[e.column]||m(t.anCells[e.column]).removeClass(s._select.className)})}),this.iterator("table",function(e,t){u(l,"deselect",["column",l[t]],!0)}),this}),l("cells().deselect()","cell().deselect()",function(){var l=this;return this.iterator("cell",function(e,t,l){t=e.aoData[t];void 0!==t._selected_cells&&(t._selected_cells[l]=!1),t.anCells&&!e.aoColumns[l]._select_selected&&m(t.anCells[l]).removeClass(e._select.className)}),this.iterator("table",function(e,t){u(l,"deselect",["cell",l[t]],!0)}),this});var g=0;return m.extend(p.ext.buttons,{selected:{text:a("selected","Selected"),className:"buttons-selected",limitTo:["rows","columns","cells"],init:function(l,e,s){var c=this;s._eventNamespace=".select"+g++,l.on(w(s),function(){var e,t;c.enable((e=l,!(-1===(t=s).limitTo.indexOf("rows")||!e.rows({selected:!0}).any())||!(-1===t.limitTo.indexOf("columns")||!e.columns({selected:!0}).any())||!(-1===t.limitTo.indexOf("cells")||!e.cells({selected:!0}).any())))}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},selectedSingle:{text:a("selectedSingle","Selected single"),className:"buttons-selected-single",init:function(t,e,l){var s=this;l._eventNamespace=".select"+g++,t.on(w(l),function(){var e=t.rows({selected:!0}).flatten().length+t.columns({selected:!0}).flatten().length+t.cells({selected:!0}).flatten().length;s.enable(1===e)}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},selectAll:{text:a("selectAll","Select all"),className:"buttons-select-all",action:function(e,t,l,s){var c=this.select.items(),n=s.selectorModifier;(n?("function"==typeof n&&(n=n.call(t,e,t,l,s)),this[c+"s"](n)):this[c+"s"]()).select()}},selectNone:{text:a("selectNone","Deselect all"),className:"buttons-select-none",action:function(){f(this.settings()[0],!0)},init:function(t,e,l){var s=this;l._eventNamespace=".select"+g++,t.on(w(l),function(){var e=t.rows({selected:!0}).flatten().length+t.columns({selected:!0}).flatten().length+t.cells({selected:!0}).flatten().length;s.enable(0<e)}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},showSelected:{text:a("showSelected","Show only selected"),className:"buttons-show-selected",action:function(e,t){var s;t.search.fixed("dt-select")?(t.search.fixed("dt-select",null),this.active(!1)):(s=t.settings()[0].aoData,t.search.fixed("dt-select",function(e,t,l){return s[l]._select_selected}),this.active(!0)),t.draw()}}}),m.each(["Row","Column","Cell"],function(e,t){var c=t.toLowerCase();p.ext.buttons["select"+t+"s"]={text:a("select"+t+"s","Select "+c+"s"),className:"buttons-select-"+c+"s",action:function(){this.select.items(c)},init:function(e){var s=this;this.active(e.select.items()===c),e.on("selectItems.dt.DT",function(e,t,l){s.active(l===c)})}}}),p.type("select-checkbox",{className:"dt-select",detect:p.versionCheck("2.1")?{oneOf:function(){return!1},allOf:function(){return!1},init:function(e,t,l){return b(t)}}:function(e){return"select-checkbox"===e&&e},order:{pre:function(e){return"X"===e?-1:0}}}),m.extend(!0,p.defaults.oLanguage,{select:{aria:{rowCheckbox:"Select row"}}}),p.render.select=function(e,t){function l(e,t,l,s){var c=s.settings.aoData[s.row],n=c._select_selected,o=s.settings.oLanguage.select.aria.rowCheckbox,a=s.settings._select.selectable;return"display"!==t?"type"===t?"select-checkbox":"filter"!==t&&n?"X":"":a&&!1===a(l,c.nTr,s.row)?"":m("<input>").attr({"aria-label":o,class:v(),name:r?r(l):null,type:"checkbox",value:i?i(l):null,checked:n}).on("input",function(e){e.preventDefault(),this.checked=m(this).closest("tr").hasClass("selected")})[0]}var i=e?p.util.get(e):null,r=t?p.util.get(t):null;return l._name="selectCheckbox",l},p.ext.order["select-checkbox"]=function(t,e){return this.api().column(e,{order:"index"}).nodes().map(function(e){return"row"===t._select.items?m(e).parent().hasClass(t._select.className).toString():"cell"===t._select.items&&m(e).hasClass(t._select.className).toString()})},m.fn.DataTable.select=p.select,m(e).on("i18n.dt.dtSelect preInit.dt.dtSelect",function(e,t){"dt"===e.namespace&&p.select.init(new p.Api(t))}),p});
@@ -1,4 +1,4 @@
1
- /*! Select for DataTables 2.0.4
1
+ /*! Select for DataTables 2.1.0
2
2
  * © SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
- import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;function cellRange(n,e,t){function l(t,l){l<t&&(e=l,l=t,t=e);var e,s=!1;return n.columns(":visible").indexes().filter(function(e){return e===t&&(s=!0),e===l?!(s=!1):s})}function s(t,l){var e,s=n.rows({search:"applied"}).indexes(),c=(s.indexOf(t)>s.indexOf(l)&&(e=l,l=t,t=e),!1);return s.filter(function(e){return e===t&&(c=!0),e===l?!(c=!1):c})}var c,t=n.cells({selected:!0}).any()||t?(c=l(t.column,e.column),s(t.row,e.row)):(c=l(0,e.column),s(0,e.row)),t=n.cells(t,c).flatten();n.cells(e,{selected:!0}).any()?n.cells(t).deselect():n.cells(t).select()}function checkboxClass(e){var t=DataTable.select.classes.checkbox;return e?t.replace(/ /g,"."):t}function disableMouseSelection(e){var t=e.settings()[0]._select.selector;$(e.table().container()).off("mousedown.dtSelect",t).off("mouseup.dtSelect",t).off("click.dtSelect",t),$("body").off("click.dtSelect"+_safeId(e.table().node()))}function enableMouseSelection(a){var o,t=$(a.table().container()),l=a.settings()[0],s=l._select.selector;t.on("mousedown.dtSelect",s,function(e){(e.shiftKey||e.metaKey||e.ctrlKey)&&t.css("-moz-user-select","none").one("selectstart.dtSelect",s,function(){return!1}),window.getSelection&&(o=window.getSelection())}).on("mouseup.dtSelect",s,function(){t.css("-moz-user-select","")}).on("click.dtSelect",s,function(e){var t,l=a.select.items();if(o){var s=window.getSelection();if((!s.anchorNode||$(s.anchorNode).closest("table")[0]===a.table().node())&&s!==o)return}var c,s=a.settings()[0],n=a.table().container();$(e.target).closest("div.dt-container")[0]==n&&(n=a.cell($(e.target).closest("td, th"))).any()&&(c=$.Event("user-select.dt"),eventTrigger(a,c,[l,n,e]),c.isDefaultPrevented()||(c=n.index(),"row"===l?(t=c.row,typeSelect(e,a,s,"row",t)):"column"===l?(t=n.index().column,typeSelect(e,a,s,"column",t)):"cell"===l&&(t=n.index(),typeSelect(e,a,s,"cell",t)),s._select_lastCell=c))}),$("body").on("click.dtSelect"+_safeId(a.table().node()),function(e){var t;!l._select.blurable||$(e.target).parents().filter(a.table().container()).length||0===$(e.target).parents("html").length||$(e.target).parents("div.DTE").length||(t=$.Event("select-blur.dt"),eventTrigger(a,t,[e.target,e]),t.isDefaultPrevented())||clear(l,!0)})}function eventTrigger(e,t,l,s){s&&!e.flatten().length||("string"==typeof t&&(t+=".dt"),l.unshift(e),$(e.table().node()).trigger(t,l))}function info(s,e){var t,l,c,n,a;"api"!==s.select.style()&&!1!==s.select.info()&&(a=s.rows({selected:!0}).flatten().length,t=s.columns({selected:!0}).flatten().length,l=s.cells({selected:!0}).flatten().length,c=function(e,t,l){e.append($('<span class="select-item"/>').append(s.i18n("select."+t+"s",{_:"%d "+t+"s selected",0:"",1:"1 "+t+" selected"},l)))},e=$(e),c(n=$('<span class="select-info"/>'),"row",a),c(n,"column",t),c(n,"cell",l),(a=e.children("span.select-info")).length&&a.remove(),""!==n.text())&&e.append(n)}function initCheckboxHeader(a,o){a.columns(".dt-select").every(function(){var n,e=this.header();$("input",e).length||(n=$("<input>").attr({class:checkboxClass(!0),type:"checkbox","aria-label":a.i18n("select.aria.headerCheckbox")||"Select all rows"}).appendTo(e).on("change",function(){this.checked?("select-page"==o?a.rows({page:"current"}):a.rows({search:"applied"})).select():a.rows({selected:!0}).deselect()}).on("click",function(e){e.stopPropagation()}),a.on("draw select deselect",function(e,t,l){var s,c;"row"!==l&&l||(l=a.rows({selected:!0}).count(),s=a.rows({search:"applied",selected:!0}).count(),c=("select-page"==o?a.rows({page:"current"}):a.rows({search:"applied"})).count(),s&&s<=l&&s===c?n.prop("checked",!0).prop("indeterminate",!1):0===s&&0===l?n.prop("checked",!1).prop("indeterminate",!1):n.prop("checked",!1).prop("indeterminate",!0))}))})}function init(a){var c=new DataTable.Api(a);a._select_init=!0,a.aoRowCreatedCallback.push(function(e,t,l){var s,c,n=a.aoData[l];for(n._select_selected&&$(e).addClass(a._select.className).find("input."+checkboxClass(!0)).prop("checked",!0),s=0,c=a.aoColumns.length;s<c;s++)(a.aoColumns[s]._select_selected||n._selected_cells&&n._selected_cells[s])&&$(n.anCells[s]).addClass(a._select.className)}),c.on("preXhr.dt.dtSelect",function(e,t){var l,s;t===c.settings()[0]&&(l=c.rows({selected:!0}).ids(!0).filter(function(e){return void 0!==e}),s=c.cells({selected:!0}).eq(0).map(function(e){var t=c.row(e.row).id(!0);return t?{row:t,column:e.column}:void 0}).filter(function(e){return void 0!==e}),c.one("draw.dt.dtSelect",function(){c.rows(l).select(),s.any()&&s.each(function(e){c.cells(e.row,e.column).select()})}))}),c.on("info.dt",function(e,t,l){t._select.infoEls.includes(l)||t._select.infoEls.push(l),info(c,l)}),c.on("select.dtSelect.dt deselect.dtSelect.dt",function(){a._select.infoEls.forEach(function(e){info(c,e)}),c.state.save()}),c.on("destroy.dtSelect",function(){$(c.rows({selected:!0}).nodes()).removeClass(c.settings()[0]._select.className),$("input."+checkboxClass(!0),c.table().header()).remove(),disableMouseSelection(c),c.off(".dtSelect"),$("body").off(".dtSelect"+_safeId(c.table().node()))})}function rowColumnRange(e,t,l,s){var c,n=e[t+"s"]({search:"applied"}).indexes(),s=n.indexOf(s),a=n.indexOf(l);e[t+"s"]({selected:!0}).any()||-1!==s?(a<s&&(c=a,a=s,s=c),n.splice(a+1,n.length),n.splice(0,s)):n.splice(n.indexOf(l)+1,n.length),e[t](l,{selected:!0}).any()?(n.splice(n.indexOf(l),1),e[t+"s"](n).deselect()):e[t+"s"](n).select()}function clear(e,t){!t&&"single"!==e._select.style||((t=new DataTable.Api(e)).rows({selected:!0}).deselect(),t.columns({selected:!0}).deselect(),t.cells({selected:!0}).deselect())}function typeSelect(e,t,l,s,c){var n=t.select.style(),a=t.select.toggleable(),o=t[s](c,{selected:!0}).any();o&&!a||("os"===n?e.ctrlKey||e.metaKey?t[s](c).select(!o):e.shiftKey?"cell"===s?cellRange(t,c,l._select_lastCell||null):rowColumnRange(t,s,c,l._select_lastCell?l._select_lastCell[s]:null):(a=t[s+"s"]({selected:!0}),o&&1===a.flatten().length?t[s](c).deselect():(a.deselect(),t[s](c).select())):"multi+shift"==n&&e.shiftKey?"cell"===s?cellRange(t,c,l._select_lastCell||null):rowColumnRange(t,s,c,l._select_lastCell?l._select_lastCell[s]:null):t[s](c).select(!o))}function _safeId(e){return e.id.replace(/[^a-zA-Z0-9\-\_]/g,"-")}DataTable.select={},DataTable.select.classes={checkbox:"dt-select-checkbox"},DataTable.select.version="2.0.4",DataTable.select.init=function(c){var e,t,l,s,n,a,o,i,r,u,d,f,h=c.settings()[0];if(!DataTable.versionCheck("2"))throw"Warning: Select requires DataTables 2 or newer";!h._select&&(e=c.state.loaded(),t=function(e,t,l){if(null!==l&&void 0!==l.select){if(c.rows({selected:!0}).any()&&c.rows().deselect(),void 0!==l.select.rows&&c.rows(l.select.rows).select(),c.columns({selected:!0}).any()&&c.columns().deselect(),void 0!==l.select.columns&&c.columns(l.select.columns).select(),c.cells({selected:!0}).any()&&c.cells().deselect(),void 0!==l.select.cells)for(var s=0;s<l.select.cells.length;s++)c.cell(l.select.cells[s].row,l.select.cells[s].column).select();c.state.save()}},c.on("stateSaveParams",function(e,t,l){l.select={},l.select.rows=c.rows({selected:!0}).ids(!0).toArray(),l.select.columns=c.columns({selected:!0})[0],l.select.cells=c.cells({selected:!0})[0].map(function(e){return{row:c.row(e.row).id(!0),column:e.column}})}).on("stateLoadParams",t).one("init",function(){t(0,0,e)}),s=h.oInit.select,l=DataTable.defaults.select,l=void 0===s?l:s,s="row",r="td, th",u="selected",f=!(d=i=o=!(a=!(n="api"))),h._select={infoEls:[]},!0===l?(n="os",f=!0):"string"==typeof l?(n=l,f=!0):$.isPlainObject(l)&&(void 0!==l.blurable&&(a=l.blurable),void 0!==l.toggleable&&(o=l.toggleable),void 0!==l.info&&(i=l.info),void 0!==l.items&&(s=l.items),f=(n=void 0!==l.style?l.style:"os",!0),void 0!==l.selector&&(r=l.selector),void 0!==l.className&&(u=l.className),void 0!==l.headerCheckbox)&&(d=l.headerCheckbox),c.select.selector(r),c.select.items(s),c.select.style(n),c.select.blurable(a),c.select.toggleable(o),c.select.info(i),h._select.className=u,!f&&$(c.table().node()).hasClass("selectable")&&c.select.style("os"),d||"select-page"===d||"select-all"===d)&&(initCheckboxHeader(c,d),c.on("init",function(){initCheckboxHeader(c,d)}))},$.each([{type:"row",prop:"aoData"},{type:"column",prop:"aoColumns"}],function(e,i){DataTable.ext.selector[i.type].push(function(e,t,l){var s,c=t.selected,n=[];if(!0!==c&&!1!==c)return l;for(var a=0,o=l.length;a<o;a++)(s=e[i.prop][l[a]])&&(!0===c&&!0===s._select_selected||!1===c&&!s._select_selected)&&n.push(l[a]);return n})}),DataTable.ext.selector.cell.push(function(e,t,l){var s,c=t.selected,n=[];if(void 0===c)return l;for(var a=0,o=l.length;a<o;a++)(s=e.aoData[l[a].row])&&(!0===c&&s._selected_cells&&!0===s._selected_cells[l[a].column]||!1===c&&(!s._selected_cells||!s._selected_cells[l[a].column]))&&n.push(l[a]);return n});var apiRegister=DataTable.Api.register,apiRegisterPlural=DataTable.Api.registerPlural;function i18n(t,l){return function(e){return e.i18n("buttons."+t,l)}}function namespacedEvents(e){e=e._eventNamespace;return"draw.dt.DT"+e+" select.dt.DT"+e+" deselect.dt.DT"+e}function enabled(e,t){return!(-1===t.limitTo.indexOf("rows")||!e.rows({selected:!0}).any())||!(-1===t.limitTo.indexOf("columns")||!e.columns({selected:!0}).any())||!(-1===t.limitTo.indexOf("cells")||!e.cells({selected:!0}).any())}apiRegister("select()",function(){return this.iterator("table",function(e){DataTable.select.init(new DataTable.Api(e))})}),apiRegister("select.blurable()",function(t){return void 0===t?this.context[0]._select.blurable:this.iterator("table",function(e){e._select.blurable=t})}),apiRegister("select.toggleable()",function(t){return void 0===t?this.context[0]._select.toggleable:this.iterator("table",function(e){e._select.toggleable=t})}),apiRegister("select.info()",function(t){return void 0===t?this.context[0]._select.info:this.iterator("table",function(e){e._select.info=t})}),apiRegister("select.items()",function(t){return void 0===t?this.context[0]._select.items:this.iterator("table",function(e){e._select.items=t,eventTrigger(new DataTable.Api(e),"selectItems",[t])})}),apiRegister("select.style()",function(l){return void 0===l?this.context[0]._select.style:this.iterator("table",function(e){e._select||DataTable.select.init(new DataTable.Api(e)),e._select_init||init(e),e._select.style=l;var t=new DataTable.Api(e);disableMouseSelection(t),"api"!==l&&enableMouseSelection(t),eventTrigger(new DataTable.Api(e),"selectStyle",[l])})}),apiRegister("select.selector()",function(t){return void 0===t?this.context[0]._select.selector:this.iterator("table",function(e){disableMouseSelection(new DataTable.Api(e)),e._select.selector=t,"api"!==e._select.style&&enableMouseSelection(new DataTable.Api(e))})}),apiRegister("select.last()",function(e){var t=this.context[0];return e?(t._select_lastCell=e,this):t._select_lastCell}),apiRegisterPlural("rows().select()","row().select()",function(e){var a=this;return!1===e?this.deselect():(this.iterator("row",function(e,t){clear(e);var l=e.aoData[t],s=e.aoColumns;$(l.nTr).addClass(e._select.className),l._select_selected=!0;for(var c=0;c<s.length;c++){var n=s[c];null===n.sType&&a.columns().types(),"select-checkbox"===n.sType&&((n=l.anCells)&&n[c]&&$("input."+checkboxClass(!0),n[c]).prop("checked",!0),null!==l._aSortData)&&(l._aSortData[c]=null)}}),this.iterator("table",function(e,t){eventTrigger(a,"select",["row",a[t]],!0)}),this)}),apiRegister("row().selected()",function(){var e=this.context[0];return!!(e&&this.length&&e.aoData[this[0]]&&e.aoData[this[0]]._select_selected)}),apiRegisterPlural("columns().select()","column().select()",function(e){var l=this;return!1===e?this.deselect():(this.iterator("column",function(e,t){clear(e),e.aoColumns[t]._select_selected=!0;t=new DataTable.Api(e).column(t);$(t.header()).addClass(e._select.className),$(t.footer()).addClass(e._select.className),t.nodes().to$().addClass(e._select.className)}),this.iterator("table",function(e,t){eventTrigger(l,"select",["column",l[t]],!0)}),this)}),apiRegister("column().selected()",function(){var e=this.context[0];return!!(e&&this.length&&e.aoColumns[this[0]]&&e.aoColumns[this[0]]._select_selected)}),apiRegisterPlural("cells().select()","cell().select()",function(e){var l=this;return!1===e?this.deselect():(this.iterator("cell",function(e,t,l){clear(e);t=e.aoData[t];void 0===t._selected_cells&&(t._selected_cells=[]),t._selected_cells[l]=!0,t.anCells&&$(t.anCells[l]).addClass(e._select.className)}),this.iterator("table",function(e,t){eventTrigger(l,"select",["cell",l.cells(l[t]).indexes().toArray()],!0)}),this)}),apiRegister("cell().selected()",function(){var e=this.context[0];if(e&&this.length){e=e.aoData[this[0][0].row];if(e&&e._selected_cells&&e._selected_cells[this[0][0].column])return!0}return!1}),apiRegisterPlural("rows().deselect()","row().deselect()",function(){var a=this;return this.iterator("row",function(e,t){var l=e.aoData[t],s=e.aoColumns;$(l.nTr).removeClass(e._select.className),l._select_selected=!1,e._select_lastCell=null;for(var c=0;c<s.length;c++){var n=s[c];null===n.sType&&a.columns().types(),"select-checkbox"===n.sType&&((n=l.anCells)&&n[c]&&$("input."+checkboxClass(!0),l.anCells[c]).prop("checked",!1),null!==l._aSortData)&&(l._aSortData[c]=null)}}),this.iterator("table",function(e,t){eventTrigger(a,"deselect",["row",a[t]],!0)}),this}),apiRegisterPlural("columns().deselect()","column().deselect()",function(){var l=this;return this.iterator("column",function(s,e){s.aoColumns[e]._select_selected=!1;var t=new DataTable.Api(s),l=t.column(e);$(l.header()).removeClass(s._select.className),$(l.footer()).removeClass(s._select.className),t.cells(null,e).indexes().each(function(e){var t=s.aoData[e.row],l=t._selected_cells;!t.anCells||l&&l[e.column]||$(t.anCells[e.column]).removeClass(s._select.className)})}),this.iterator("table",function(e,t){eventTrigger(l,"deselect",["column",l[t]],!0)}),this}),apiRegisterPlural("cells().deselect()","cell().deselect()",function(){var l=this;return this.iterator("cell",function(e,t,l){t=e.aoData[t];void 0!==t._selected_cells&&(t._selected_cells[l]=!1),t.anCells&&!e.aoColumns[l]._select_selected&&$(t.anCells[l]).removeClass(e._select.className)}),this.iterator("table",function(e,t){eventTrigger(l,"deselect",["cell",l[t]],!0)}),this});var _buttonNamespace=0;$.extend(DataTable.ext.buttons,{selected:{text:i18n("selected","Selected"),className:"buttons-selected",limitTo:["rows","columns","cells"],init:function(e,t,l){var s=this;l._eventNamespace=".select"+_buttonNamespace++,e.on(namespacedEvents(l),function(){s.enable(enabled(e,l))}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},selectedSingle:{text:i18n("selectedSingle","Selected single"),className:"buttons-selected-single",init:function(t,e,l){var s=this;l._eventNamespace=".select"+_buttonNamespace++,t.on(namespacedEvents(l),function(){var e=t.rows({selected:!0}).flatten().length+t.columns({selected:!0}).flatten().length+t.cells({selected:!0}).flatten().length;s.enable(1===e)}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},selectAll:{text:i18n("selectAll","Select all"),className:"buttons-select-all",action:function(e,t,l,s){var c=this.select.items(),n=s.selectorModifier;(n?("function"==typeof n&&(n=n.call(t,e,t,l,s)),this[c+"s"](n)):this[c+"s"]()).select()}},selectNone:{text:i18n("selectNone","Deselect all"),className:"buttons-select-none",action:function(){clear(this.settings()[0],!0)},init:function(t,e,l){var s=this;l._eventNamespace=".select"+_buttonNamespace++,t.on(namespacedEvents(l),function(){var e=t.rows({selected:!0}).flatten().length+t.columns({selected:!0}).flatten().length+t.cells({selected:!0}).flatten().length;s.enable(0<e)}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},showSelected:{text:i18n("showSelected","Show only selected"),className:"buttons-show-selected",action:function(e,t){var s;t.search.fixed("dt-select")?(t.search.fixed("dt-select",null),this.active(!1)):(s=t.settings()[0].aoData,t.search.fixed("dt-select",function(e,t,l){return s[l]._select_selected}),this.active(!0)),t.draw()}}}),$.each(["Row","Column","Cell"],function(e,t){var c=t.toLowerCase();DataTable.ext.buttons["select"+t+"s"]={text:i18n("select"+t+"s","Select "+c+"s"),className:"buttons-select-"+c+"s",action:function(){this.select.items(c)},init:function(e){var s=this;e.on("selectItems.dt.DT",function(e,t,l){s.active(l===c)})}}}),DataTable.type("select-checkbox",{className:"dt-select",detect:DataTable.versionCheck("2.1")?{oneOf:function(){return!1},allOf:function(){return!1},init:function(e,t,l){return t.mRender&&"selectCheckbox"===t.mRender.name}}:function(e){return"select-checkbox"===e&&e},order:{pre:function(e){return"X"===e?-1:0}}}),$.extend(!0,DataTable.defaults.oLanguage,{select:{aria:{rowCheckbox:"Select row"}}}),DataTable.render.select=function(e,t){var n=e?DataTable.util.get(e):null,a=t?DataTable.util.get(t):null;return function(e,t,l,s){var c=s.settings.aoData[s.row]._select_selected,s=s.settings.oLanguage.select.aria.rowCheckbox;return"display"===t?$("<input>").attr({"aria-label":s,class:checkboxClass(),name:a?a(l):null,type:"checkbox",value:n?n(l):null,checked:c}).on("input",function(e){e.preventDefault(),this.checked=$(this).closest("tr").hasClass("selected")})[0]:"type"===t?"select-checkbox":"filter"!==t&&c?"X":""}},DataTable.ext.order["select-checkbox"]=function(t,e){return this.api().column(e,{order:"index"}).nodes().map(function(e){return"row"===t._select.items?$(e).parent().hasClass(t._select.className).toString():"cell"===t._select.items&&$(e).hasClass(t._select.className).toString()})},$.fn.DataTable.select=DataTable.select,$(document).on("preInit.dt.dtSelect",function(e,t){"dt"===e.namespace&&DataTable.select.init(new DataTable.Api(t))});export default DataTable;
4
+ import jQuery from"jquery";import DataTable from"datatables.net";let $=jQuery;function cellRange(n,e,t){function l(t,l){l<t&&(e=l,l=t,t=e);var e,s=!1;return n.columns(":visible").indexes().filter(function(e){return e===t&&(s=!0),e===l?!(s=!1):s})}function s(t,l){var e,s=n.rows({search:"applied"}).indexes(),c=(s.indexOf(t)>s.indexOf(l)&&(e=l,l=t,t=e),!1);return s.filter(function(e){return e===t&&(c=!0),e===l?!(c=!1):c})}var c,t=n.cells({selected:!0}).any()||t?(c=l(t.column,e.column),s(t.row,e.row)):(c=l(0,e.column),s(0,e.row)),t=n.cells(t,c).flatten();n.cells(e,{selected:!0}).any()?n.cells(t).deselect():n.cells(t).select()}function checkboxClass(e){var t=DataTable.select.classes.checkbox;return e?t.replace(/ /g,"."):t}function disableMouseSelection(e){var t=e.settings()[0]._select.selector;$(e.table().container()).off("mousedown.dtSelect",t).off("mouseup.dtSelect",t).off("click.dtSelect",t),$("body").off("click.dtSelect"+_safeId(e.table().node()))}function enableMouseSelection(a){var o,t=$(a.table().container()),l=a.settings()[0],s=l._select.selector;t.on("mousedown.dtSelect",s,function(e){(e.shiftKey||e.metaKey||e.ctrlKey)&&t.css("-moz-user-select","none").one("selectstart.dtSelect",s,function(){return!1}),window.getSelection&&(o=window.getSelection())}).on("mouseup.dtSelect",s,function(){t.css("-moz-user-select","")}).on("click.dtSelect",s,function(e){var t,l=a.select.items();if(o){var s=window.getSelection();if((!s.anchorNode||$(s.anchorNode).closest("table")[0]===a.table().node())&&s!==o)return}var c,s=a.settings()[0],n=a.table().container();$(e.target).closest("div.dt-container")[0]==n&&(n=a.cell($(e.target).closest("td, th"))).any()&&(c=$.Event("user-select.dt"),eventTrigger(a,c,[l,n,e]),c.isDefaultPrevented()||(c=n.index(),"row"===l?(t=c.row,typeSelect(e,a,s,"row",t)):"column"===l?(t=n.index().column,typeSelect(e,a,s,"column",t)):"cell"===l&&(t=n.index(),typeSelect(e,a,s,"cell",t)),s._select_lastCell=c))}),$("body").on("click.dtSelect"+_safeId(a.table().node()),function(e){var t;!l._select.blurable||$(e.target).parents().filter(a.table().container()).length||0===$(e.target).parents("html").length||$(e.target).parents("div.DTE").length||(t=$.Event("select-blur.dt"),eventTrigger(a,t,[e.target,e]),t.isDefaultPrevented())||clear(l,!0)})}function eventTrigger(e,t,l,s){s&&!e.flatten().length||("string"==typeof t&&(t+=".dt"),l.unshift(e),$(e.table().node()).trigger(t,l))}function isCheckboxColumn(e){return e.mRender&&"selectCheckbox"===e.mRender._name}function info(s,e){var t,l,c,n,a;"api"!==s.select.style()&&!1!==s.select.info()&&(a=s.settings()[0]._select_set.length||s.rows({selected:!0}).count(),t=s.columns({selected:!0}).count(),l=s.cells({selected:!0}).count(),c=function(e,t,l){e.append($('<span class="select-item"/>').append(s.i18n("select."+t+"s",{_:"%d "+t+"s selected",0:"",1:"1 "+t+" selected"},l)))},e=$(e),c(n=$('<span class="select-info"/>'),"row",a),c(n,"column",t),c(n,"cell",l),(a=e.children("span.select-info")).length&&a.remove(),""!==n.text())&&e.append(n)}function initCheckboxHeader(c,n){var l=c.settings()[0].aoColumns;c.columns().iterator("column",function(e,t){var s;isCheckboxColumn(l[t])&&(t=c.column(t).header(),$("input",t).length||(s=$("<input>").attr({class:checkboxClass(!0),type:"checkbox","aria-label":c.i18n("select.aria.headerCheckbox")||"Select all rows"}).appendTo(t).on("change",function(){this.checked?("select-page"==n?c.rows({page:"current"}):c.rows({search:"applied"})).select():("select-page"==n?c.rows({page:"current",selected:!0}):c.rows({selected:!0})).deselect()}).on("click",function(e){e.stopPropagation()}),c.on("draw select deselect",function(e,t,l){"row"!==l&&l||((l=headerCheckboxState(c,n)).search&&l.search<=l.count&&l.search===l.available?s.prop("checked",!0).prop("indeterminate",!1):0===l.search&&0===l.count?s.prop("checked",!1).prop("indeterminate",!1):s.prop("checked",!1).prop("indeterminate",!0))})))})}function headerCheckboxState(e,t){var l=e.settings()[0],s=l._select.selectable,c=0,n=("select-page"==t?e.rows({page:"current",selected:!0}):e.rows({selected:!0})).count(),a=("select-page"==t?e.rows({page:"current",selected:!0}):e.rows({search:"applied",selected:!0})).count();if(s)for(var o=("select-page"==t?e.rows({page:"current"}):e.rows({search:"applied"})).indexes(),i=0;i<o.length;i++){var r=l.aoData[o[i]];s(r._aData,r.nTr,o[i])&&c++}else c=("select-page"==t?e.rows({page:"current"}):e.rows({search:"applied"})).count();return{available:c,count:n,search:a}}function init(a){var o=new DataTable.Api(a);a._select_init=!0,a._select_set=[],a.aoRowCreatedCallback.push(function(e,t,l){var s,c,n=a.aoData[l],l=o.row(l).id();for((n._select_selected||"undefined"!==l&&a._select_set.includes(l))&&(n._select_selected=!0,$(e).addClass(a._select.className).find("input."+checkboxClass(!0)).prop("checked",!0)),s=0,c=a.aoColumns.length;s<c;s++)(a.aoColumns[s]._select_selected||n._selected_cells&&n._selected_cells[s])&&$(n.anCells[s]).addClass(a._select.className)}),_cumulativeEvents(o),o.on("info.dt",function(e,t,l){t._select.infoEls.includes(l)||t._select.infoEls.push(l),info(o,l)}),o.on("select.dtSelect.dt deselect.dtSelect.dt",function(){a._select.infoEls.forEach(function(e){info(o,e)}),o.state.save()}),o.on("destroy.dtSelect",function(){$(o.rows({selected:!0}).nodes()).removeClass(o.settings()[0]._select.className),$("input."+checkboxClass(!0),o.table().header()).remove(),disableMouseSelection(o),o.off(".dtSelect"),$("body").off(".dtSelect"+_safeId(o.table().node()))})}function rowColumnRange(e,t,l,s){var c,n=e[t+"s"]({search:"applied"}).indexes(),s=n.indexOf(s),a=n.indexOf(l);e[t+"s"]({selected:!0}).any()||-1!==s?(a<s&&(c=a,a=s,s=c),n.splice(a+1,n.length),n.splice(0,s)):n.splice(n.indexOf(l)+1,n.length),e[t](l,{selected:!0}).any()?(n.splice(n.indexOf(l),1),e[t+"s"](n).deselect()):e[t+"s"](n).select()}function clear(e,t){!t&&"single"!==e._select.style||((t=new DataTable.Api(e)).rows({selected:!0}).deselect(),t.columns({selected:!0}).deselect(),t.cells({selected:!0}).deselect())}function typeSelect(e,t,l,s,c){var n=t.select.style(),a=t.select.toggleable(),o=t[s](c,{selected:!0}).any();o&&!a||("os"===n?e.ctrlKey||e.metaKey?t[s](c).select(!o):e.shiftKey?"cell"===s?cellRange(t,c,l._select_lastCell||null):rowColumnRange(t,s,c,l._select_lastCell?l._select_lastCell[s]:null):(a=t[s+"s"]({selected:!0}),o&&1===a.flatten().length?t[s](c).deselect():(a.deselect(),t[s](c).select())):"multi+shift"==n&&e.shiftKey?"cell"===s?cellRange(t,c,l._select_lastCell||null):rowColumnRange(t,s,c,l._select_lastCell?l._select_lastCell[s]:null):t[s](c).select(!o))}function _safeId(e){return e.id.replace(/[^a-zA-Z0-9\-\_]/g,"-")}function _cumulativeEvents(c){c.on("select",function(e,t,l,s){"row"===l&&(l=c.settings()[0],_add(c,l._select_set,s))}),c.on("deselect",function(e,t,l,s){"row"===l&&(l=c.settings()[0],_remove(c,l._select_set,s))})}function _add(e,t,l){for(var s=0;s<l.length;s++){var c=e.row(l[s]).id();c&&"undefined"!==c&&!t.includes(c)&&t.push(c)}}function _remove(e,t,l){for(var s=0;s<l.length;s++){var c=e.row(l[s]).id(),c=t.indexOf(c);-1!==c&&t.splice(c,1)}}DataTable.select={},DataTable.select.classes={checkbox:"dt-select-checkbox"},DataTable.select.version="2.1.0",DataTable.select.init=function(c){var e,t,l,s,n,a,o,i,r,u,d,f,h,p=c.settings()[0];if(!DataTable.versionCheck("2"))throw"Warning: Select requires DataTables 2 or newer";!p._select&&(e=c.state.loaded(),t=function(e,t,l){if(null!==l&&void 0!==l.select){if(c.rows({selected:!0}).any()&&c.rows().deselect(),void 0!==l.select.rows&&c.rows(l.select.rows).select(),c.columns({selected:!0}).any()&&c.columns().deselect(),void 0!==l.select.columns&&c.columns(l.select.columns).select(),c.cells({selected:!0}).any()&&c.cells().deselect(),void 0!==l.select.cells)for(var s=0;s<l.select.cells.length;s++)c.cell(l.select.cells[s].row,l.select.cells[s].column).select();c.state.save()}},c.on("stateSaveParams",function(e,t,l){l.select={},l.select.rows=c.rows({selected:!0}).ids(!0).toArray(),l.select.columns=c.columns({selected:!0})[0],l.select.cells=c.cells({selected:!0})[0].map(function(e){return{row:c.row(e.row).id(!0),column:e.column}})}).on("stateLoadParams",t).one("init",function(){t(0,0,e)}),s=p.oInit.select,l=DataTable.defaults.select,l=void 0===s?l:s,s="row",o=!(a=!(n="api")),u="td, th",d="selected",h=!(f=r=!(i=null)),p._select={infoEls:[]},!0===l?(n="os",h=!0):"string"==typeof l?(n=l,h=!0):$.isPlainObject(l)&&(void 0!==l.blurable&&(a=l.blurable),void 0!==l.toggleable&&(o=l.toggleable),void 0!==l.info&&(r=l.info),void 0!==l.items&&(s=l.items),h=(n=void 0!==l.style?l.style:"os",!0),void 0!==l.selector&&(u=l.selector),void 0!==l.className&&(d=l.className),void 0!==l.headerCheckbox&&(f=l.headerCheckbox),void 0!==l.selectable)&&(i=l.selectable),c.select.selector(u),c.select.items(s),c.select.style(n),c.select.blurable(a),c.select.toggleable(o),c.select.info(r),c.select.selectable(i),p._select.className=d,!h&&$(c.table().node()).hasClass("selectable")&&c.select.style("os"),f||"select-page"===f||"select-all"===f)&&c.ready(function(){initCheckboxHeader(c,f)})},$.each([{type:"row",prop:"aoData"},{type:"column",prop:"aoColumns"}],function(e,i){DataTable.ext.selector[i.type].push(function(e,t,l){var s,c=t.selected,n=[];if(!0!==c&&!1!==c)return l;for(var a=0,o=l.length;a<o;a++)(s=e[i.prop][l[a]])&&(!0===c&&!0===s._select_selected||!1===c&&!s._select_selected)&&n.push(l[a]);return n})}),DataTable.ext.selector.cell.push(function(e,t,l){var s,c=t.selected,n=[];if(void 0===c)return l;for(var a=0,o=l.length;a<o;a++)(s=e.aoData[l[a].row])&&(!0===c&&s._selected_cells&&!0===s._selected_cells[l[a].column]||!1===c&&(!s._selected_cells||!s._selected_cells[l[a].column]))&&n.push(l[a]);return n});var apiRegister=DataTable.Api.register,apiRegisterPlural=DataTable.Api.registerPlural;function i18n(t,l){return function(e){return e.i18n("buttons."+t,l)}}function namespacedEvents(e){e=e._eventNamespace;return"draw.dt.DT"+e+" select.dt.DT"+e+" deselect.dt.DT"+e}function enabled(e,t){return!(-1===t.limitTo.indexOf("rows")||!e.rows({selected:!0}).any())||!(-1===t.limitTo.indexOf("columns")||!e.columns({selected:!0}).any())||!(-1===t.limitTo.indexOf("cells")||!e.cells({selected:!0}).any())}apiRegister("select()",function(){return this.iterator("table",function(e){DataTable.select.init(new DataTable.Api(e))})}),apiRegister("select.blurable()",function(t){return void 0===t?this.context[0]._select.blurable:this.iterator("table",function(e){e._select.blurable=t})}),apiRegister("select.toggleable()",function(t){return void 0===t?this.context[0]._select.toggleable:this.iterator("table",function(e){e._select.toggleable=t})}),apiRegister("select.info()",function(t){return void 0===t?this.context[0]._select.info:this.iterator("table",function(e){e._select.info=t})}),apiRegister("select.items()",function(t){return void 0===t?this.context[0]._select.items:this.iterator("table",function(e){e._select.items=t,eventTrigger(new DataTable.Api(e),"selectItems",[t])})}),apiRegister("select.style()",function(l){return void 0===l?this.context[0]._select.style:this.iterator("table",function(e){e._select||DataTable.select.init(new DataTable.Api(e)),e._select_init||init(e),e._select.style=l;var t=new DataTable.Api(e);"api"!==l?t.ready(function(){disableMouseSelection(t),enableMouseSelection(t)}):disableMouseSelection(t),eventTrigger(new DataTable.Api(e),"selectStyle",[l])})}),apiRegister("select.selector()",function(s){return void 0===s?this.context[0]._select.selector:this.iterator("table",function(e){var t=new DataTable.Api(e),l=e._select.style;disableMouseSelection(t),e._select.selector=s,l&&"api"!==l?t.ready(function(){disableMouseSelection(t),enableMouseSelection(t)}):disableMouseSelection(t)})}),apiRegister("select.selectable()",function(e){var t=this.context[0];return e?(t._select.selectable=e,this):t._select.selectable}),apiRegister("select.last()",function(e){var t=this.context[0];return e?(t._select_lastCell=e,this):t._select_lastCell}),apiRegister("select.cumulative()",function(){var e=this.context[0];return e&&e._select_set?e._select_set:[]}),apiRegisterPlural("rows().select()","row().select()",function(e){var a=this,o=[];return!1===e?this.deselect():(this.iterator("row",function(e,t){clear(e);var l=e.aoData[t],s=e.aoColumns;if(e._select.selectable&&!1===e._select.selectable(l._aData,l.nTr,t))return;$(l.nTr).addClass(e._select.className),l._select_selected=!0,o.push(t);for(var c=0;c<s.length;c++){var n=s[c];null===n.sType&&a.columns().types(),isCheckboxColumn(n)&&((n=l.anCells)&&n[c]&&$("input."+checkboxClass(!0),n[c]).prop("checked",!0),null!==l._aSortData)&&(l._aSortData[c]=null)}}),this.iterator("table",function(e){eventTrigger(a,"select",["row",o],!0)}),this)}),apiRegister("row().selected()",function(){var e=this.context[0];return!!(e&&this.length&&e.aoData[this[0]]&&e.aoData[this[0]]._select_selected)}),apiRegisterPlural("columns().select()","column().select()",function(e){var l=this;return!1===e?this.deselect():(this.iterator("column",function(e,t){clear(e),e.aoColumns[t]._select_selected=!0;t=new DataTable.Api(e).column(t);$(t.header()).addClass(e._select.className),$(t.footer()).addClass(e._select.className),t.nodes().to$().addClass(e._select.className)}),this.iterator("table",function(e,t){eventTrigger(l,"select",["column",l[t]],!0)}),this)}),apiRegister("column().selected()",function(){var e=this.context[0];return!!(e&&this.length&&e.aoColumns[this[0]]&&e.aoColumns[this[0]]._select_selected)}),apiRegisterPlural("cells().select()","cell().select()",function(e){var l=this;return!1===e?this.deselect():(this.iterator("cell",function(e,t,l){clear(e);t=e.aoData[t];void 0===t._selected_cells&&(t._selected_cells=[]),t._selected_cells[l]=!0,t.anCells&&$(t.anCells[l]).addClass(e._select.className)}),this.iterator("table",function(e,t){eventTrigger(l,"select",["cell",l.cells(l[t]).indexes().toArray()],!0)}),this)}),apiRegister("cell().selected()",function(){var e=this.context[0];if(e&&this.length){e=e.aoData[this[0][0].row];if(e&&e._selected_cells&&e._selected_cells[this[0][0].column])return!0}return!1}),apiRegisterPlural("rows().deselect()","row().deselect()",function(){var a=this;return this.iterator("row",function(e,t){var l=e.aoData[t],s=e.aoColumns;$(l.nTr).removeClass(e._select.className),l._select_selected=!1,e._select_lastCell=null;for(var c=0;c<s.length;c++){var n=s[c];null===n.sType&&a.columns().types(),isCheckboxColumn(n)&&((n=l.anCells)&&n[c]&&$("input."+checkboxClass(!0),l.anCells[c]).prop("checked",!1),null!==l._aSortData)&&(l._aSortData[c]=null)}}),this.iterator("table",function(e,t){eventTrigger(a,"deselect",["row",a[t]],!0)}),this}),apiRegisterPlural("columns().deselect()","column().deselect()",function(){var l=this;return this.iterator("column",function(s,e){s.aoColumns[e]._select_selected=!1;var t=new DataTable.Api(s),l=t.column(e);$(l.header()).removeClass(s._select.className),$(l.footer()).removeClass(s._select.className),t.cells(null,e).indexes().each(function(e){var t=s.aoData[e.row],l=t._selected_cells;!t.anCells||l&&l[e.column]||$(t.anCells[e.column]).removeClass(s._select.className)})}),this.iterator("table",function(e,t){eventTrigger(l,"deselect",["column",l[t]],!0)}),this}),apiRegisterPlural("cells().deselect()","cell().deselect()",function(){var l=this;return this.iterator("cell",function(e,t,l){t=e.aoData[t];void 0!==t._selected_cells&&(t._selected_cells[l]=!1),t.anCells&&!e.aoColumns[l]._select_selected&&$(t.anCells[l]).removeClass(e._select.className)}),this.iterator("table",function(e,t){eventTrigger(l,"deselect",["cell",l[t]],!0)}),this});var _buttonNamespace=0;$.extend(DataTable.ext.buttons,{selected:{text:i18n("selected","Selected"),className:"buttons-selected",limitTo:["rows","columns","cells"],init:function(e,t,l){var s=this;l._eventNamespace=".select"+_buttonNamespace++,e.on(namespacedEvents(l),function(){s.enable(enabled(e,l))}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},selectedSingle:{text:i18n("selectedSingle","Selected single"),className:"buttons-selected-single",init:function(t,e,l){var s=this;l._eventNamespace=".select"+_buttonNamespace++,t.on(namespacedEvents(l),function(){var e=t.rows({selected:!0}).flatten().length+t.columns({selected:!0}).flatten().length+t.cells({selected:!0}).flatten().length;s.enable(1===e)}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},selectAll:{text:i18n("selectAll","Select all"),className:"buttons-select-all",action:function(e,t,l,s){var c=this.select.items(),n=s.selectorModifier;(n?("function"==typeof n&&(n=n.call(t,e,t,l,s)),this[c+"s"](n)):this[c+"s"]()).select()}},selectNone:{text:i18n("selectNone","Deselect all"),className:"buttons-select-none",action:function(){clear(this.settings()[0],!0)},init:function(t,e,l){var s=this;l._eventNamespace=".select"+_buttonNamespace++,t.on(namespacedEvents(l),function(){var e=t.rows({selected:!0}).flatten().length+t.columns({selected:!0}).flatten().length+t.cells({selected:!0}).flatten().length;s.enable(0<e)}),this.disable()},destroy:function(e,t,l){e.off(l._eventNamespace)}},showSelected:{text:i18n("showSelected","Show only selected"),className:"buttons-show-selected",action:function(e,t){var s;t.search.fixed("dt-select")?(t.search.fixed("dt-select",null),this.active(!1)):(s=t.settings()[0].aoData,t.search.fixed("dt-select",function(e,t,l){return s[l]._select_selected}),this.active(!0)),t.draw()}}}),$.each(["Row","Column","Cell"],function(e,t){var c=t.toLowerCase();DataTable.ext.buttons["select"+t+"s"]={text:i18n("select"+t+"s","Select "+c+"s"),className:"buttons-select-"+c+"s",action:function(){this.select.items(c)},init:function(e){var s=this;this.active(e.select.items()===c),e.on("selectItems.dt.DT",function(e,t,l){s.active(l===c)})}}}),DataTable.type("select-checkbox",{className:"dt-select",detect:DataTable.versionCheck("2.1")?{oneOf:function(){return!1},allOf:function(){return!1},init:function(e,t,l){return isCheckboxColumn(t)}}:function(e){return"select-checkbox"===e&&e},order:{pre:function(e){return"X"===e?-1:0}}}),$.extend(!0,DataTable.defaults.oLanguage,{select:{aria:{rowCheckbox:"Select row"}}}),DataTable.render.select=function(e,t){function l(e,t,l,s){var c=s.settings.aoData[s.row],n=c._select_selected,a=s.settings.oLanguage.select.aria.rowCheckbox,o=s.settings._select.selectable;return"display"!==t?"type"===t?"select-checkbox":"filter"!==t&&n?"X":"":o&&!1===o(l,c.nTr,s.row)?"":$("<input>").attr({"aria-label":a,class:checkboxClass(),name:r?r(l):null,type:"checkbox",value:i?i(l):null,checked:n}).on("input",function(e){e.preventDefault(),this.checked=$(this).closest("tr").hasClass("selected")})[0]}var i=e?DataTable.util.get(e):null,r=t?DataTable.util.get(t):null;return l._name="selectCheckbox",l},DataTable.ext.order["select-checkbox"]=function(t,e){return this.api().column(e,{order:"index"}).nodes().map(function(e){return"row"===t._select.items?$(e).parent().hasClass(t._select.className).toString():"cell"===t._select.items&&$(e).hasClass(t._select.className).toString()})},$.fn.DataTable.select=DataTable.select,$(document).on("i18n.dt.dtSelect preInit.dt.dtSelect",function(e,t){"dt"===e.namespace&&DataTable.select.init(new DataTable.Api(t))});export default DataTable;
@@ -1,4 +1,4 @@
1
- /*! Select for DataTables 2.0.4
1
+ /*! Select for DataTables 2.1.0
2
2
  * © SpryMedia Ltd - datatables.net/license/mit
3
3
  */
4
4
 
@@ -16,7 +16,7 @@ DataTable.select.classes = {
16
16
  checkbox: 'dt-select-checkbox'
17
17
  };
18
18
 
19
- DataTable.select.version = '2.0.4';
19
+ DataTable.select.version = '2.1.0';
20
20
 
21
21
  DataTable.select.init = function (dt) {
22
22
  var ctx = dt.settings()[0];
@@ -86,6 +86,7 @@ DataTable.select.init = function (dt) {
86
86
  var style = 'api';
87
87
  var blurable = false;
88
88
  var toggleable = true;
89
+ var selectable = null;
89
90
  var info = true;
90
91
  var selector = 'td, th';
91
92
  var className = 'selected';
@@ -142,6 +143,10 @@ DataTable.select.init = function (dt) {
142
143
  if (opts.headerCheckbox !== undefined) {
143
144
  headerCheckbox = opts.headerCheckbox;
144
145
  }
146
+
147
+ if (opts.selectable !== undefined) {
148
+ selectable = opts.selectable;
149
+ }
145
150
  }
146
151
 
147
152
  dt.select.selector(selector);
@@ -150,6 +155,7 @@ DataTable.select.init = function (dt) {
150
155
  dt.select.blurable(blurable);
151
156
  dt.select.toggleable(toggleable);
152
157
  dt.select.info(info);
158
+ dt.select.selectable(selectable);
153
159
  ctx._select.className = className;
154
160
 
155
161
  // If the init options haven't enabled select, but there is a selectable
@@ -159,11 +165,9 @@ DataTable.select.init = function (dt) {
159
165
  }
160
166
 
161
167
  // Insert a checkbox into the header if needed - might need to wait
162
- // for init complete, or it might already be done
168
+ // for init complete
163
169
  if (headerCheckbox || headerCheckbox === 'select-page' || headerCheckbox === 'select-all') {
164
- initCheckboxHeader(dt, headerCheckbox);
165
-
166
- dt.on('init', function () {
170
+ dt.ready(function () {
167
171
  initCheckboxHeader(dt, headerCheckbox);
168
172
  });
169
173
  }
@@ -509,6 +513,15 @@ function eventTrigger(api, type, args, any) {
509
513
  $(api.table().node()).trigger(type, args);
510
514
  }
511
515
 
516
+ /**
517
+ * Determine if a column is a checkbox column
518
+ * @param {*} col DataTables column object
519
+ * @returns
520
+ */
521
+ function isCheckboxColumn(col) {
522
+ return col.mRender && col.mRender._name === 'selectCheckbox';
523
+ }
524
+
512
525
  /**
513
526
  * Update the information element of the DataTable showing information about the
514
527
  * items selected. This is done by adding tags to the existing text
@@ -521,9 +534,13 @@ function info(api, node) {
521
534
  return;
522
535
  }
523
536
 
524
- var rows = api.rows({ selected: true }).flatten().length;
525
- var columns = api.columns({ selected: true }).flatten().length;
526
- var cells = api.cells({ selected: true }).flatten().length;
537
+ // If _select_set has any length, then ids are available and should be used
538
+ // as the counter. Otherwise use the API to workout how many rows are
539
+ // selected.
540
+ var rowSetLength = api.settings()[0]._select_set.length;
541
+ var rows = rowSetLength ? rowSetLength : api.rows({ selected: true }).count();
542
+ var columns = api.columns({ selected: true }).count();
543
+ var cells = api.cells({ selected: true }).count();
527
544
 
528
545
  var add = function (el, name, num) {
529
546
  el.append(
@@ -563,9 +580,18 @@ function info(api, node) {
563
580
  * @param {*} headerCheckbox the header checkbox option
564
581
  */
565
582
  function initCheckboxHeader( dt, headerCheckbox ) {
583
+ var dtSettings = dt.settings()[0];
584
+ var dtInternalColumns = dtSettings.aoColumns;
585
+
566
586
  // Find any checkbox column(s)
567
- dt.columns('.dt-select').every(function () {
568
- var header = this.header();
587
+ dt.columns().iterator('column', function (s, idx) {
588
+ var col = dtInternalColumns[idx];
589
+
590
+ // Checkbox columns have a rendering function with a given name
591
+ if (! isCheckboxColumn(col)) {
592
+ return;
593
+ }
594
+ var header = dt.column(idx).header();
569
595
 
570
596
  if (! $('input', header).length) {
571
597
  // If no checkbox yet, insert one
@@ -579,33 +605,36 @@ function initCheckboxHeader( dt, headerCheckbox ) {
579
605
  .on('change', function () {
580
606
  if (this.checked) {
581
607
  if (headerCheckbox == 'select-page') {
582
- dt.rows({page: 'current'}).select()
608
+ dt.rows({page: 'current'}).select();
583
609
  } else {
584
610
  dt.rows({search: 'applied'}).select();
585
611
  }
586
612
  }
587
613
  else {
588
- dt.rows({selected: true}).deselect();
614
+ if (headerCheckbox == 'select-page') {
615
+ dt.rows({page: 'current', selected: true}).deselect();
616
+ }
617
+ else {
618
+ dt.rows({selected: true}).deselect();
619
+ }
589
620
  }
590
621
  })
591
622
  .on('click', function (e) {
592
623
  e.stopPropagation();
593
624
  });
594
-
625
+
595
626
  // Update the header checkbox's state when the selection in the
596
627
  // table changes
597
628
  dt.on('draw select deselect', function (e, pass, type) {
598
629
  if (type === 'row' || ! type) {
599
- var count = dt.rows({selected: true}).count();
600
- var search = dt.rows({search: 'applied', selected: true}).count();
601
- var available = headerCheckbox == 'select-page' ? dt.rows({page: 'current'}).count() : dt.rows({search: 'applied'}).count();
630
+ var nums = headerCheckboxState(dt, headerCheckbox);
602
631
 
603
- if (search && search <= count && search === available) {
632
+ if (nums.search && nums.search <= nums.count && nums.search === nums.available) {
604
633
  input
605
634
  .prop('checked', true)
606
635
  .prop('indeterminate', false);
607
636
  }
608
- else if (search === 0 && count === 0) {
637
+ else if (nums.search === 0 && nums.count === 0) {
609
638
  input
610
639
  .prop('checked', false)
611
640
  .prop('indeterminate', false);
@@ -621,6 +650,54 @@ function initCheckboxHeader( dt, headerCheckbox ) {
621
650
  });
622
651
  }
623
652
 
653
+ /**
654
+ * Determine the counts used to define the header checkbox's state
655
+ *
656
+ * @param {*} dt DT API
657
+ * @param {*} headerCheckbox Configuration for what the header checkbox does
658
+ * @returns Counts object
659
+ */
660
+ function headerCheckboxState(dt, headerCheckbox) {
661
+ var ctx = dt.settings()[0];
662
+ var selectable = ctx._select.selectable;
663
+ var available = 0;
664
+ var count = headerCheckbox == 'select-page'
665
+ ? dt.rows({page: 'current', selected: true}).count()
666
+ : dt.rows({selected: true}).count();
667
+ var search = headerCheckbox == 'select-page'
668
+ ? dt.rows({page: 'current', selected: true}).count()
669
+ : dt.rows({search: 'applied', selected: true}).count();
670
+
671
+ if (! selectable) {
672
+ available = headerCheckbox == 'select-page'
673
+ ? dt.rows({page: 'current'}).count()
674
+ : dt.rows({search: 'applied'}).count();
675
+ }
676
+ else {
677
+ // Need to count how many rows are actually selectable to know if all selectable
678
+ // rows are selected or not
679
+ var indexes = headerCheckbox == 'select-page'
680
+ ? dt.rows({page: 'current'}).indexes()
681
+ : dt.rows({search: 'applied'}).indexes();
682
+
683
+ for (var i=0 ; i<indexes.length ; i++) {
684
+ // For speed I use the internal DataTables object.
685
+ var rowInternal = ctx.aoData[indexes[i]];
686
+ var result = selectable(rowInternal._aData, rowInternal.nTr, indexes[i]);
687
+
688
+ if (result) {
689
+ available++;
690
+ }
691
+ }
692
+ }
693
+
694
+ return {
695
+ available: available,
696
+ count: count,
697
+ search: search
698
+ }
699
+ }
700
+
624
701
  /**
625
702
  * Initialisation of a new table. Attach event handlers and callbacks to allow
626
703
  * Select to operate correctly.
@@ -635,6 +712,9 @@ function init(ctx) {
635
712
  var api = new DataTable.Api(ctx);
636
713
  ctx._select_init = true;
637
714
 
715
+ // _select_set contains a list of the ids of all rows that are selected
716
+ ctx._select_set = [];
717
+
638
718
  // Row callback so that classes can be added to rows and cells if the item
639
719
  // was selected before the element was created. This will happen with the
640
720
  // `deferRender` option enabled.
@@ -645,9 +725,15 @@ function init(ctx) {
645
725
  ctx.aoRowCreatedCallback.push(function (row, data, index) {
646
726
  var i, ien;
647
727
  var d = ctx.aoData[index];
728
+ var id = api.row(index).id();
648
729
 
649
730
  // Row
650
- if (d._select_selected) {
731
+ if (
732
+ d._select_selected ||
733
+ (id !== 'undefined' && ctx._select_set.includes(id))
734
+ ) {
735
+ d._select_selected = true;
736
+
651
737
  $(row)
652
738
  .addClass(ctx._select.className)
653
739
  .find('input.' + checkboxClass(true)).prop('checked', true);
@@ -666,46 +752,7 @@ function init(ctx) {
666
752
  }
667
753
  );
668
754
 
669
- // On Ajax reload we want to reselect all rows which are currently selected,
670
- // if there is an rowId (i.e. a unique value to identify each row with)
671
- api.on('preXhr.dt.dtSelect', function (e, settings) {
672
- if (settings !== api.settings()[0]) {
673
- // Not triggered by our DataTable!
674
- return;
675
- }
676
-
677
- // note that column selection doesn't need to be cached and then
678
- // reselected, as they are already selected
679
- var rows = api
680
- .rows({ selected: true })
681
- .ids(true)
682
- .filter(function (d) {
683
- return d !== undefined;
684
- });
685
-
686
- var cells = api
687
- .cells({ selected: true })
688
- .eq(0)
689
- .map(function (cellIdx) {
690
- var id = api.row(cellIdx.row).id(true);
691
- return id ? { row: id, column: cellIdx.column } : undefined;
692
- })
693
- .filter(function (d) {
694
- return d !== undefined;
695
- });
696
-
697
- // On the next draw, reselect the currently selected items
698
- api.one('draw.dt.dtSelect', function () {
699
- api.rows(rows).select();
700
-
701
- // `cells` is not a cell index selector, so it needs a loop
702
- if (cells.any()) {
703
- cells.each(function (id) {
704
- api.cells(id.row, id.column).select();
705
- });
706
- }
707
- });
708
- });
755
+ _cumulativeEvents(api);
709
756
 
710
757
  // Update the table information element with selected item summary
711
758
  api.on('info.dt', function (e, ctx, node) {
@@ -878,6 +925,57 @@ function _safeId(node) {
878
925
  return node.id.replace(/[^a-zA-Z0-9\-\_]/g, '-');
879
926
  }
880
927
 
928
+ /**
929
+ * Set up event handlers for cumulative selection
930
+ *
931
+ * @param {*} api DT API instance
932
+ */
933
+ function _cumulativeEvents(api) {
934
+ // Add event listeners to add / remove from the _select_set
935
+ api.on('select', function (e, dt, type, indexes) {
936
+ // Only support for rows at the moment
937
+ if (type !== 'row') {
938
+ return;
939
+ }
940
+
941
+ var ctx = api.settings()[0];
942
+
943
+ _add(api, ctx._select_set, indexes);
944
+ });
945
+
946
+ api.on('deselect', function (e, dt, type, indexes) {
947
+ // Only support for rows at the moment
948
+ if (type !== 'row') {
949
+ return;
950
+ }
951
+
952
+ var ctx = api.settings()[0];
953
+
954
+ _remove(api, ctx._select_set, indexes);
955
+ });
956
+ }
957
+
958
+ function _add(api, arr, indexes) {
959
+ for (var i=0 ; i<indexes.length ; i++) {
960
+ var id = api.row(indexes[i]).id();
961
+
962
+ if (id && id !== 'undefined' && ! arr.includes(id)) {
963
+ arr.push(id);
964
+ }
965
+ }
966
+ }
967
+
968
+ function _remove(api, arr, indexes) {
969
+ for (var i=0 ; i<indexes.length ; i++) {
970
+ var id = api.row(indexes[i]).id();
971
+ var idx = arr.indexOf(id);
972
+
973
+ if (idx !== -1) {
974
+ arr.splice(idx, 1);
975
+ }
976
+ }
977
+ }
978
+
881
979
  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
882
980
  * DataTables selectors
883
981
  */
@@ -1026,10 +1124,15 @@ apiRegister('select.style()', function (style) {
1026
1124
  // Add / remove mouse event handlers. They aren't required when only
1027
1125
  // API selection is available
1028
1126
  var dt = new DataTable.Api(ctx);
1029
- disableMouseSelection(dt);
1030
1127
 
1031
1128
  if (style !== 'api') {
1032
- enableMouseSelection(dt);
1129
+ dt.ready(function () {
1130
+ disableMouseSelection(dt);
1131
+ enableMouseSelection(dt);
1132
+ });
1133
+ }
1134
+ else {
1135
+ disableMouseSelection(dt);
1033
1136
  }
1034
1137
 
1035
1138
  eventTrigger(new DataTable.Api(ctx), 'selectStyle', [style]);
@@ -1042,16 +1145,36 @@ apiRegister('select.selector()', function (selector) {
1042
1145
  }
1043
1146
 
1044
1147
  return this.iterator('table', function (ctx) {
1045
- disableMouseSelection(new DataTable.Api(ctx));
1148
+ var dt = new DataTable.Api(ctx);
1149
+ var style = ctx._select.style;
1150
+
1151
+ disableMouseSelection(dt);
1046
1152
 
1047
1153
  ctx._select.selector = selector;
1048
1154
 
1049
- if (ctx._select.style !== 'api') {
1050
- enableMouseSelection(new DataTable.Api(ctx));
1155
+ if (style && style !== 'api') {
1156
+ dt.ready(function () {
1157
+ disableMouseSelection(dt);
1158
+ enableMouseSelection(dt);
1159
+ });
1160
+ }
1161
+ else {
1162
+ disableMouseSelection(dt);
1051
1163
  }
1052
1164
  });
1053
1165
  });
1054
1166
 
1167
+ apiRegister('select.selectable()', function (set) {
1168
+ let ctx = this.context[0];
1169
+
1170
+ if (set) {
1171
+ ctx._select.selectable = set;
1172
+ return this;
1173
+ }
1174
+
1175
+ return ctx._select.selectable;
1176
+ });
1177
+
1055
1178
  apiRegister('select.last()', function (set) {
1056
1179
  let ctx = this.context[0];
1057
1180
 
@@ -1063,8 +1186,17 @@ apiRegister('select.last()', function (set) {
1063
1186
  return ctx._select_lastCell;
1064
1187
  });
1065
1188
 
1189
+ apiRegister('select.cumulative()', function () {
1190
+ let ctx = this.context[0];
1191
+
1192
+ return ctx && ctx._select_set
1193
+ ? ctx._select_set
1194
+ : [];
1195
+ });
1196
+
1066
1197
  apiRegisterPlural('rows().select()', 'row().select()', function (select) {
1067
1198
  var api = this;
1199
+ var selectedIndexes = [];
1068
1200
 
1069
1201
  if (select === false) {
1070
1202
  return this.deselect();
@@ -1079,9 +1211,20 @@ apiRegisterPlural('rows().select()', 'row().select()', function (select) {
1079
1211
  var dtData = ctx.aoData[idx];
1080
1212
  var dtColumns = ctx.aoColumns;
1081
1213
 
1214
+ if (ctx._select.selectable) {
1215
+ var result = ctx._select.selectable(dtData._aData, dtData.nTr, idx);
1216
+
1217
+ if (result === false) {
1218
+ // Not selectable - do nothing
1219
+ return;
1220
+ }
1221
+ }
1222
+
1082
1223
  $(dtData.nTr).addClass(ctx._select.className);
1083
1224
  dtData._select_selected = true;
1084
1225
 
1226
+ selectedIndexes.push(idx);
1227
+
1085
1228
  for (var i=0 ; i<dtColumns.length ; i++) {
1086
1229
  var col = dtColumns[i];
1087
1230
 
@@ -1090,7 +1233,7 @@ apiRegisterPlural('rows().select()', 'row().select()', function (select) {
1090
1233
  api.columns().types()
1091
1234
  }
1092
1235
 
1093
- if (col.sType === 'select-checkbox') {
1236
+ if (isCheckboxColumn(col)) {
1094
1237
  var cells = dtData.anCells;
1095
1238
 
1096
1239
  // Make sure the checkbox shows the right state
@@ -1106,8 +1249,8 @@ apiRegisterPlural('rows().select()', 'row().select()', function (select) {
1106
1249
  }
1107
1250
  });
1108
1251
 
1109
- this.iterator('table', function (ctx, i) {
1110
- eventTrigger(api, 'select', ['row', api[i]], true);
1252
+ this.iterator('table', function (ct) {
1253
+ eventTrigger(api, 'select', ['row', selectedIndexes], true);
1111
1254
  });
1112
1255
 
1113
1256
  return this;
@@ -1224,7 +1367,7 @@ apiRegisterPlural('rows().deselect()', 'row().deselect()', function () {
1224
1367
  api.columns().types()
1225
1368
  }
1226
1369
 
1227
- if (col.sType === 'select-checkbox') {
1370
+ if (isCheckboxColumn(col)) {
1228
1371
  var cells = dtData.anCells;
1229
1372
 
1230
1373
  // Make sure the checkbox shows the right state
@@ -1469,6 +1612,8 @@ $.each(['Row', 'Column', 'Cell'], function (i, item) {
1469
1612
  init: function (dt) {
1470
1613
  var that = this;
1471
1614
 
1615
+ this.active(dt.select.items() === lc);
1616
+
1472
1617
  dt.on('selectItems.dt.DT', function (e, ctx, items) {
1473
1618
  that.active(items === lc);
1474
1619
  });
@@ -1477,7 +1622,7 @@ $.each(['Row', 'Column', 'Cell'], function (i, item) {
1477
1622
  });
1478
1623
 
1479
1624
  // Note that DataTables 2.1 has more robust type detection, but we retain
1480
- // backwards compatbility with 2.0 for the moment.
1625
+ // backwards compatibility with 2.0 for the moment.
1481
1626
  DataTable.type('select-checkbox', {
1482
1627
  className: 'dt-select',
1483
1628
  detect: DataTable.versionCheck('2.1')
@@ -1489,7 +1634,7 @@ DataTable.type('select-checkbox', {
1489
1634
  return false; // no op
1490
1635
  },
1491
1636
  init: function (settings, col, idx) {
1492
- return col.mRender && col.mRender.name === 'selectCheckbox';
1637
+ return isCheckboxColumn(col);
1493
1638
  }
1494
1639
  }
1495
1640
  : function (data) {
@@ -1515,12 +1660,22 @@ DataTable.render.select = function (valueProp, nameProp) {
1515
1660
  var valueFn = valueProp ? DataTable.util.get(valueProp) : null;
1516
1661
  var nameFn = nameProp ? DataTable.util.get(nameProp) : null;
1517
1662
 
1518
- return function selectCheckbox(data, type, row, meta) {
1663
+ var fn = function (data, type, row, meta) {
1519
1664
  var dtRow = meta.settings.aoData[meta.row];
1520
1665
  var selected = dtRow._select_selected;
1521
1666
  var ariaLabel = meta.settings.oLanguage.select.aria.rowCheckbox;
1667
+ var selectable = meta.settings._select.selectable;
1522
1668
 
1523
1669
  if (type === 'display') {
1670
+ // Check if the row is selectable before showing the checkbox
1671
+ if (selectable) {
1672
+ var result = selectable(row, dtRow.nTr, meta.row);
1673
+
1674
+ if (result === false) {
1675
+ return '';
1676
+ }
1677
+ }
1678
+
1524
1679
  return $('<input>')
1525
1680
  .attr({
1526
1681
  'aria-label': ariaLabel,
@@ -1549,6 +1704,12 @@ DataTable.render.select = function (valueProp, nameProp) {
1549
1704
 
1550
1705
  return selected ? 'X' : '';
1551
1706
  }
1707
+
1708
+ // Workaround so uglify doesn't strip the function name. It is used
1709
+ // for the column type detection.
1710
+ fn._name = 'selectCheckbox';
1711
+
1712
+ return fn;
1552
1713
  }
1553
1714
 
1554
1715
  // Legacy checkbox ordering
@@ -1573,11 +1734,10 @@ $.fn.DataTable.select = DataTable.select;
1573
1734
  * Initialisation
1574
1735
  */
1575
1736
 
1576
- // DataTables creation - check if select has been defined in the options. Note
1577
- // this required that the table be in the document! If it isn't then something
1578
- // needs to trigger this method unfortunately. The next major release of
1579
- // DataTables will rework the events and address this.
1580
- $(document).on('preInit.dt.dtSelect', function (e, ctx) {
1737
+ // DataTables creation - we need this to run _before_ data is read in, but
1738
+ // for backwards compat. we also run again on preInit. If it happens twice
1739
+ // it will simply do nothing the second time around.
1740
+ $(document).on('i18n.dt.dtSelect preInit.dt.dtSelect', function (e, ctx) {
1581
1741
  if (e.namespace !== 'dt') {
1582
1742
  return;
1583
1743
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "main": "js/dataTables.select.js",
5
5
  "module": "js/dataTables.select.mjs",
6
6
  "types": "./types/types.d.ts",
7
- "version": "2.0.4",
7
+ "version": "2.1.0",
8
8
  "files": [
9
9
  "js/**/*.js",
10
10
  "js/**/*.mjs",
package/types/types.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  /// <reference types="jquery" />
9
9
 
10
- import DataTables from 'datatables.net';
10
+ import DataTables, {ObjectColumnRender} from 'datatables.net';
11
11
 
12
12
  export default DataTables;
13
13
 
@@ -107,6 +107,26 @@ declare module 'datatables.net' {
107
107
  version: string;
108
108
  }
109
109
  }
110
+
111
+ interface DataTablesStaticRender {
112
+ /**
113
+ * Display a checkbox in the column's cells to be used for and represent
114
+ * row selection.
115
+ */
116
+ select(): ObjectColumnRender;
117
+
118
+ /**
119
+ * Display a checkbox in the column's cells to be used for and represent
120
+ * row selection, with the `value` and `name` attributes for the checkbox
121
+ * `input` being set by properties from the row's data object.
122
+ *
123
+ * @param valueProp Name of the data property where the `value` for the
124
+ * checkbox is.
125
+ * @param nameProp Name of the data property where the `name` for the
126
+ * checkbox is.
127
+ */
128
+ select(valueProp: string, nameProp: string): ObjectColumnRender;
129
+ }
110
130
  }
111
131
 
112
132
  interface ConfigSelect {