blob: b4f0b9531acc96f816f2ca1fa95841a296a3ac01 [file] [log] [blame]
SurenNewareba91c492020-10-27 14:18:54 +05301export const selectedRows = [];
2export const tableHeaderCheckboxModel = false;
3export const tableHeaderCheckboxIndeterminate = false;
4
Yoshie Muranaka183c2752020-02-12 11:30:49 -08005const BVTableSelectableMixin = {
Yoshie Muranaka183c2752020-02-12 11:30:49 -08006 methods: {
7 clearSelectedRows(tableRef) {
8 if (tableRef) tableRef.clearSelected();
9 },
10 toggleSelectRow(tableRef, rowIndex) {
11 if (tableRef && rowIndex !== undefined) {
12 tableRef.isRowSelected(rowIndex)
13 ? tableRef.unselectRow(rowIndex)
14 : tableRef.selectRow(rowIndex);
15 }
16 },
17 onRowSelected(selectedRows, totalRowsCount) {
18 if (selectedRows && totalRowsCount !== undefined) {
19 this.selectedRows = selectedRows;
20 if (selectedRows.length === 0) {
21 this.tableHeaderCheckboxIndeterminate = false;
22 this.tableHeaderCheckboxModel = false;
23 } else if (selectedRows.length === totalRowsCount) {
24 this.tableHeaderCheckboxIndeterminate = false;
25 this.tableHeaderCheckboxModel = true;
26 } else {
27 this.tableHeaderCheckboxIndeterminate = true;
Sukanya Pandey7a57faa2021-04-30 14:26:19 +053028 this.tableHeaderCheckboxModel = true;
Yoshie Muranaka183c2752020-02-12 11:30:49 -080029 }
30 }
31 },
32 onChangeHeaderCheckbox(tableRef) {
33 if (tableRef) {
Sukanya Pandey7a57faa2021-04-30 14:26:19 +053034 if (this.tableHeaderCheckboxModel) tableRef.selectAllRows();
35 else tableRef.clearSelected();
Yoshie Muranaka183c2752020-02-12 11:30:49 -080036 }
Derick Montague602e98a2020-10-21 16:20:00 -050037 },
38 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080039};
40
41export default BVTableSelectableMixin;