summaryrefslogtreecommitdiff
path: root/src/components/_sila/Mixins/BVTableSelectableMixin.js
blob: b4f0b9531acc96f816f2ca1fa95841a296a3ac01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export const selectedRows = [];
export const tableHeaderCheckboxModel = false;
export const tableHeaderCheckboxIndeterminate = false;

const BVTableSelectableMixin = {
  methods: {
    clearSelectedRows(tableRef) {
      if (tableRef) tableRef.clearSelected();
    },
    toggleSelectRow(tableRef, rowIndex) {
      if (tableRef && rowIndex !== undefined) {
        tableRef.isRowSelected(rowIndex)
          ? tableRef.unselectRow(rowIndex)
          : tableRef.selectRow(rowIndex);
      }
    },
    onRowSelected(selectedRows, totalRowsCount) {
      if (selectedRows && totalRowsCount !== undefined) {
        this.selectedRows = selectedRows;
        if (selectedRows.length === 0) {
          this.tableHeaderCheckboxIndeterminate = false;
          this.tableHeaderCheckboxModel = false;
        } else if (selectedRows.length === totalRowsCount) {
          this.tableHeaderCheckboxIndeterminate = false;
          this.tableHeaderCheckboxModel = true;
        } else {
          this.tableHeaderCheckboxIndeterminate = true;
          this.tableHeaderCheckboxModel = true;
        }
      }
    },
    onChangeHeaderCheckbox(tableRef) {
      if (tableRef) {
        if (this.tableHeaderCheckboxModel) tableRef.selectAllRows();
        else tableRef.clearSelected();
      }
    },
  },
};

export default BVTableSelectableMixin;