blob: cee7d0c9739e2f25ebe25b0a84daea47d4867085 [file] [log] [blame]
Yoshie Muranaka183c2752020-02-12 11:30:49 -08001const BVTableSelectableMixin = {
2 data() {
3 return {
4 tableHeaderCheckboxModel: false,
5 tableHeaderCheckboxIndeterminate: false,
Derick Montague602e98a2020-10-21 16:20:00 -05006 selectedRows: [],
Yoshie Muranaka183c2752020-02-12 11:30:49 -08007 };
8 },
9 methods: {
10 clearSelectedRows(tableRef) {
11 if (tableRef) tableRef.clearSelected();
12 },
13 toggleSelectRow(tableRef, rowIndex) {
14 if (tableRef && rowIndex !== undefined) {
15 tableRef.isRowSelected(rowIndex)
16 ? tableRef.unselectRow(rowIndex)
17 : tableRef.selectRow(rowIndex);
18 }
19 },
20 onRowSelected(selectedRows, totalRowsCount) {
21 if (selectedRows && totalRowsCount !== undefined) {
22 this.selectedRows = selectedRows;
23 if (selectedRows.length === 0) {
24 this.tableHeaderCheckboxIndeterminate = false;
25 this.tableHeaderCheckboxModel = false;
26 } else if (selectedRows.length === totalRowsCount) {
27 this.tableHeaderCheckboxIndeterminate = false;
28 this.tableHeaderCheckboxModel = true;
29 } else {
30 this.tableHeaderCheckboxIndeterminate = true;
31 this.tableHeaderCheckboxModel = false;
32 }
33 }
34 },
35 onChangeHeaderCheckbox(tableRef) {
36 if (tableRef) {
37 if (this.tableHeaderCheckboxModel) tableRef.clearSelected();
38 else tableRef.selectAllRows();
39 }
Derick Montague602e98a2020-10-21 16:20:00 -050040 },
41 },
Yoshie Muranaka183c2752020-02-12 11:30:49 -080042};
43
44export default BVTableSelectableMixin;