|
28 | 28 | :style="cellStyles" |
29 | 29 | > |
30 | 30 | <v-checkbox |
31 | | - v-model="isAllSelected" |
| 31 | + v-if="selectStrategy !== 'single'" |
32 | 32 | :class="checkBoxClasses" |
33 | 33 | :density="density" |
34 | 34 | :focused="false" |
35 | 35 | :indeterminate="isIndeterminate" |
| 36 | + :model-value="isAllSelected" |
| 37 | + @update:modelValue="selectAllBoxes" |
36 | 38 | ></v-checkbox> |
37 | 39 | </th> |
38 | 40 | <!-- Column Render `data-table-expand` --> |
@@ -92,19 +94,30 @@ const emit = defineEmits([ |
92 | 94 |
|
93 | 95 | const props = withDefaults(defineProps<TFootSlotProps>(), {}); |
94 | 96 |
|
| 97 | +const allSelectable = ref(); |
95 | 98 | const theme = useTheme(); |
96 | 99 | const isAllSelected = ref<boolean>(props.slotProps.allRowsSelected); |
| 100 | +const items = ref(props.items); |
| 101 | +const tableModelValue = computed(() => props.tableModelValue); |
97 | 102 |
|
98 | | -const allSelected = computed(() => props.slotProps.allRowsSelected || isAllSelected.value); |
99 | 103 | const columns = computed<Column[] | Props['footers']>(() => { |
100 | 104 | if (props.footers.length) { |
101 | 105 | return props.footers; |
102 | 106 | } |
103 | 107 |
|
104 | 108 | return props.slotProps.columns; |
105 | 109 | }); |
106 | | -const someSelected = computed(() => props.slotProps.someSelected); |
107 | | -const isIndeterminate = computed(() => someSelected.value && !props.slotProps.allRowsSelected); |
| 110 | +
|
| 111 | +
|
| 112 | +watch(() => props.items, (newItems) => { |
| 113 | + items.value = newItems; |
| 114 | +
|
| 115 | + allSelectable.value = newItems?.filter(item => item.selectable) ?? []; |
| 116 | +
|
| 117 | + allSelectable.value = newItems?.filter(item => { |
| 118 | + return item.selectable !== false; |
| 119 | + }); |
| 120 | +}); |
108 | 121 |
|
109 | 122 |
|
110 | 123 | // -------------------------------------------------- Tfoot // |
@@ -143,21 +156,31 @@ const cellStyles = computed<CSSProperties>(() => { |
143 | 156 |
|
144 | 157 |
|
145 | 158 | // -------------------------------------------------- Select // |
146 | | -watch(isAllSelected, (newVal) => { |
147 | | - props.slotProps.selectAll(newVal); |
148 | | - emit('click:selectAll', isAllSelected.value); |
| 159 | +const isIndeterminate = computed(() => { |
| 160 | + if (props.slotProps.allSelected || tableModelValue?.value?.length === 0) { |
| 161 | + return false; |
| 162 | + } |
| 163 | +
|
| 164 | + return true; |
149 | 165 | }); |
150 | 166 |
|
151 | | -watch(allSelected, (newVal) => { |
152 | | - isAllSelected.value = newVal; |
| 167 | +watch(() => props.slotProps.allSelected, (newAllSelected) => { |
| 168 | + isAllSelected.value = newAllSelected as boolean; |
153 | 169 | }); |
154 | 170 |
|
155 | | -watch(someSelected, (newVal) => { |
156 | | - if (!newVal) { |
157 | | - isAllSelected.value = false; |
| 171 | +watch(() => props.slotProps.someSelected, () => { |
| 172 | + if (props.slotProps.allSelected) { |
| 173 | + return false; |
158 | 174 | } |
159 | 175 | }); |
160 | 176 |
|
| 177 | +function selectAllBoxes() { |
| 178 | + isAllSelected.value = !isAllSelected.value; |
| 179 | + props.slotProps.selectAll(isAllSelected.value); |
| 180 | +
|
| 181 | + emit('click:selectAll', isAllSelected.value); |
| 182 | +} |
| 183 | +
|
161 | 184 | const checkBoxClasses = computed<object>(() => { |
162 | 185 | return useCheckBoxClasses({ level: props.level }); |
163 | 186 | }); |
|
0 commit comments