blob: cee7d0c9739e2f25ebe25b0a84daea47d4867085 [file] [log] [blame]
const BVTableSelectableMixin = {
data() {
return {
tableHeaderCheckboxModel: false,
tableHeaderCheckboxIndeterminate: false,
selectedRows: [],
};
},
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 = false;
}
}
},
onChangeHeaderCheckbox(tableRef) {
if (tableRef) {
if (this.tableHeaderCheckboxModel) tableRef.clearSelected();
else tableRef.selectAllRows();
}
},
},
};
export default BVTableSelectableMixin;