SurenNeware | ba91c49 | 2020-10-27 14:18:54 +0530 | [diff] [blame] | 1 | export const selectedRows = []; |
| 2 | export const tableHeaderCheckboxModel = false; |
| 3 | export const tableHeaderCheckboxIndeterminate = false; |
| 4 | |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 5 | const BVTableSelectableMixin = { |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 6 | 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 Pandey | 7a57faa | 2021-04-30 14:26:19 +0530 | [diff] [blame] | 28 | this.tableHeaderCheckboxModel = true; |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 29 | } |
| 30 | } |
| 31 | }, |
| 32 | onChangeHeaderCheckbox(tableRef) { |
| 33 | if (tableRef) { |
Sukanya Pandey | 7a57faa | 2021-04-30 14:26:19 +0530 | [diff] [blame] | 34 | if (this.tableHeaderCheckboxModel) tableRef.selectAllRows(); |
| 35 | else tableRef.clearSelected(); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 36 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 37 | }, |
| 38 | }, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | export default BVTableSelectableMixin; |