diff --git a/src/runtime/components/data/Table.vue b/src/runtime/components/data/Table.vue index 26f6fada..bb64c860 100644 --- a/src/runtime/components/data/Table.vue +++ b/src/runtime/components/data/Table.vue @@ -10,7 +10,7 @@ selected.value && selected.value.length > 0 && selected.value.length < props.rows.length) + const getStringifiedSet = (arr: TableRow[]) => new Set(arr.map(item => JSON.stringify(item))) + + const totalRows = computed(() => props.rows.length) + + const countCheckedRow = computed(() => { + const selectedData = getStringifiedSet(selected.value) + const rowsData = getStringifiedSet(props.rows) + + return Array.from(selectedData).filter(item => rowsData.has(item)).length + }) + + const indeterminate = computed(() => { + if (!selected.value || !props.rows) return false + return countCheckedRow.value > 0 && countCheckedRow.value < totalRows.value + }) + + const isAllRowChecked = computed(() => countCheckedRow.value === totalRows.value) const emptyState = computed(() => { if (props.emptyState === null) return null @@ -411,6 +427,7 @@ export default defineComponent({ emptyState, // eslint-disable-next-line vue/no-dupe-keys loadingState, + isAllRowChecked, onChangeCheckbox, openedRows, isSelected,