Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 1 | const BVTableSelectableMixin = { |
| 2 | data() { |
| 3 | return { |
| 4 | tableHeaderCheckboxModel: false, |
| 5 | tableHeaderCheckboxIndeterminate: false, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 6 | selectedRows: [], |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 7 | }; |
| 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame^] | 40 | }, |
| 41 | }, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | export default BVTableSelectableMixin; |