1const BVTableSelectableMixin = { 2 data() { 3 return { 4 tableHeaderCheckboxModel: false, 5 tableHeaderCheckboxIndeterminate: false, 6 selectedRows: [] 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 } 40 } 41 } 42}; 43 44export default BVTableSelectableMixin; 45