1 var _typeof = typeof Symbol ===
"function" && typeof Symbol.iterator ===
"symbol" ?
function (obj) {
return typeof obj; } :
function (obj) {
return obj && typeof Symbol ===
"function" && obj.constructor === Symbol && obj !== Symbol.prototype ?
"symbol" : typeof obj; };
5 var SelectRow =
function SelectRow(table) {
7 this.selecting =
false;
8 this.lastClickedRow =
false;
10 this.selectedRows = [];
11 this.headerCheckboxElement = null;
14 SelectRow.prototype.clearSelectionData =
function (silent) {
15 this.selecting =
false;
16 this.lastClickedRow =
false;
18 this.selectedRows = [];
21 this._rowSelectionChanged();
25 SelectRow.prototype.initializeRow =
function (row) {
27 element = row.getElement();
30 var endSelect =
function endSelect() {
32 setTimeout(
function () {
33 self.selecting =
false;
36 document.body.removeEventListener(
"mouseup", endSelect);
39 row.modules.select = { selected:
false };
42 if (
self.table.options.selectableCheck.call(
this.table, row.getComponent())) {
43 element.classList.add(
"tabulator-selectable");
44 element.classList.remove(
"tabulator-unselectable");
46 if (
self.table.options.selectable &&
self.table.options.selectable !=
"highlight") {
47 if (
self.table.options.selectableRangeMode ===
"click") {
48 element.addEventListener(
"click",
function (e) {
50 self.table._clearSelection();
51 self.lastClickedRow =
self.lastClickedRow || row;
53 var lastClickedRowIdx =
self.table.rowManager.getDisplayRowIndex(
self.lastClickedRow);
54 var rowIdx =
self.table.rowManager.getDisplayRowIndex(row);
56 var fromRowIdx = lastClickedRowIdx <= rowIdx ? lastClickedRowIdx : rowIdx;
57 var toRowIdx = lastClickedRowIdx >= rowIdx ? lastClickedRowIdx : rowIdx;
59 var rows =
self.table.rowManager.getDisplayRows().slice(0);
60 var toggledRows = rows.splice(fromRowIdx, toRowIdx - fromRowIdx + 1);
62 if (e.ctrlKey || e.metaKey) {
63 toggledRows.forEach(
function (toggledRow) {
64 if (toggledRow !==
self.lastClickedRow) {
66 if (
self.table.options.selectable !==
true && !
self.isRowSelected(row)) {
67 if (
self.selectedRows.length <
self.table.options.selectable) {
68 self.toggleRow(toggledRow);
71 self.toggleRow(toggledRow);
75 self.lastClickedRow = row;
79 if (
self.table.options.selectable !==
true) {
80 if (toggledRows.length >
self.table.options.selectable) {
81 toggledRows = toggledRows.slice(0,
self.table.options.selectable);
85 self.selectRows(toggledRows);
87 self.table._clearSelection();
88 }
else if (e.ctrlKey || e.metaKey) {
90 self.lastClickedRow = row;
94 self.lastClickedRow = row;
98 element.addEventListener(
"click",
function (e) {
99 if (!
self.table.modExists(
"edit") || !
self.table.modules.edit.getCurrentCell()) {
100 self.table._clearSelection();
103 if (!
self.selecting) {
108 element.addEventListener(
"mousedown",
function (e) {
110 self.table._clearSelection();
112 self.selecting =
true;
114 self.selectPrev = [];
116 document.body.addEventListener(
"mouseup", endSelect);
117 document.body.addEventListener(
"keyup", endSelect);
125 element.addEventListener(
"mouseenter",
function (e) {
126 if (
self.selecting) {
127 self.table._clearSelection();
130 if (
self.selectPrev[1] == row) {
131 self.toggleRow(
self.selectPrev[0]);
136 element.addEventListener(
"mouseout",
function (e) {
137 if (
self.selecting) {
138 self.table._clearSelection();
139 self.selectPrev.unshift(row);
145 element.classList.add(
"tabulator-unselectable");
146 element.classList.remove(
"tabulator-selectable");
151 SelectRow.prototype.toggleRow =
function (row) {
152 if (this.table.options.selectableCheck.call(
this.table, row.getComponent())) {
153 if (row.modules.select && row.modules.select.selected) {
154 this._deselectRow(row);
156 this._selectRow(row);
162 SelectRow.prototype.selectRows =
function (rows) {
167 switch (typeof rows ===
"undefined" ?
"undefined" : _typeof(rows)) {
169 this.table.rowManager.rows.forEach(
function (row) {
170 _this._selectRow(row,
true,
true);
173 this._rowSelectionChanged();
178 rowMatch = this.table.rowManager.findRow(rows);
181 this._selectRow(rowMatch,
true,
true);
183 this.table.rowManager.getRows(rows).forEach(
function (row) {
184 _this._selectRow(row,
true,
true);
188 this._rowSelectionChanged();
192 if (Array.isArray(rows)) {
193 rows.forEach(
function (row) {
194 _this._selectRow(row,
true,
true);
197 this._rowSelectionChanged();
199 this._selectRow(rows,
false,
true);
206 SelectRow.prototype._selectRow =
function (rowInfo, silent, force) {
210 if (!isNaN(this.table.options.selectable) && this.table.options.selectable !==
true && !force) {
211 if (this.selectedRows.length >=
this.table.options.selectable) {
212 if (this.table.options.selectableRollingSelection) {
213 this._deselectRow(this.selectedRows[0]);
220 var row = this.table.rowManager.findRow(rowInfo);
223 if (this.selectedRows.indexOf(row) == -1) {
224 if (!row.modules.select) {
225 row.modules.select = {};
228 row.modules.select.selected =
true;
229 if (row.modules.select.checkboxEl) {
230 row.modules.select.checkboxEl.checked =
true;
232 row.getElement().classList.add(
"tabulator-selected");
234 this.selectedRows.push(row);
237 this.table.options.rowSelected.call(this.table, row.getComponent());
238 this._rowSelectionChanged();
243 console.warn(
"Selection Error - No such row found, ignoring selection:" + rowInfo);
248 SelectRow.prototype.isRowSelected =
function (row) {
249 return this.selectedRows.indexOf(row) !== -1;
253 SelectRow.prototype.deselectRows =
function (rows) {
257 if (typeof rows ==
"undefined") {
259 rowCount =
self.selectedRows.length;
261 for (var i = 0; i < rowCount; i++) {
262 self._deselectRow(
self.selectedRows[0],
true);
265 self._rowSelectionChanged();
267 if (Array.isArray(rows)) {
268 rows.forEach(
function (row) {
269 self._deselectRow(row,
true);
272 self._rowSelectionChanged();
274 self._deselectRow(rows);
280 SelectRow.prototype._deselectRow =
function (rowInfo, silent) {
282 row =
self.table.rowManager.findRow(rowInfo),
286 index =
self.selectedRows.findIndex(
function (selectedRow) {
287 return selectedRow == row;
292 if (!row.modules.select) {
293 row.modules.select = {};
296 row.modules.select.selected =
false;
297 if (row.modules.select.checkboxEl) {
298 row.modules.select.checkboxEl.checked =
false;
300 row.getElement().classList.remove(
"tabulator-selected");
301 self.selectedRows.splice(index, 1);
304 self.table.options.rowDeselected.call(this.table, row.getComponent());
305 self._rowSelectionChanged();
310 console.warn(
"Deselection Error - No such row found, ignoring selection:" + rowInfo);
315 SelectRow.prototype.getSelectedData =
function () {
318 this.selectedRows.forEach(
function (row) {
319 data.push(row.getData());
325 SelectRow.prototype.getSelectedRows =
function () {
329 this.selectedRows.forEach(
function (row) {
330 rows.push(row.getComponent());
336 SelectRow.prototype._rowSelectionChanged =
function () {
337 if (this.headerCheckboxElement) {
338 if (this.selectedRows.length === 0) {
339 this.headerCheckboxElement.checked =
false;
340 this.headerCheckboxElement.indeterminate =
false;
341 }
else if (this.table.rowManager.rows.length ===
this.selectedRows.length) {
342 this.headerCheckboxElement.checked =
true;
343 this.headerCheckboxElement.indeterminate =
false;
345 this.headerCheckboxElement.indeterminate =
true;
346 this.headerCheckboxElement.checked =
false;
350 this.table.options.rowSelectionChanged.call(this.table, this.getSelectedData(), this.getSelectedRows());
353 SelectRow.prototype.registerRowSelectCheckbox =
function (row, element) {
354 if (!row._row.modules.select) {
355 row._row.modules.select = {};
358 row._row.modules.select.checkboxEl = element;
361 SelectRow.prototype.registerHeaderSelectCheckbox =
function (element) {
362 this.headerCheckboxElement = element;
365 Tabulator.prototype.registerModule(
"selectRow", SelectRow);