|
16 | 16 | </tr> |
17 | 17 | </thead> |
18 | 18 | <tbody> |
| 19 | + <SkeleteLoader |
| 20 | + v-if="isLoading" |
| 21 | + :rows="pageSize" |
| 22 | + :columns="columns.length" |
| 23 | + :row-heights="rowHeights" |
| 24 | + :column-widths="columnWidths" |
| 25 | + /> |
19 | 26 | <tr |
| 27 | + v-else="!isLoading" |
20 | 28 | v-for="(item, index) in dataPage" |
21 | 29 | :class="{ |
22 | 30 | 'afcl-table-body odd:bg-lightTableOddBackground odd:dark:bg-darkTableOddBackground even:bg-lightTableEvenBackground even:dark:bg-darkTableEvenBackground': evenHighlights, |
|
111 | 119 | </template> |
112 | 120 |
|
113 | 121 | <script setup lang="ts"> |
114 | | - import { ref, type Ref, computed } from 'vue'; |
| 122 | + import { ref, type Ref, computed, useTemplateRef, watch } from 'vue'; |
115 | 123 | import { asyncComputed } from '@vueuse/core'; |
116 | | - import { Skeleton } from '@/afcl'; |
| 124 | + import SkeleteLoader from '@/components/SkeleteLoader.vue'; |
117 | 125 |
|
118 | 126 | const props = withDefaults( |
119 | 127 | defineProps<{ |
|
135 | 143 | const currentPage = ref(1); |
136 | 144 | const isLoading = ref(false); |
137 | 145 | const pageInput = ref('1'); |
| 146 | + const rowRefs = useTemplateRef<HTMLElement[]>('rowRefs'); |
| 147 | + const headerRefs = useTemplateRef<HTMLElement[]>('headerRefs'); |
| 148 | + const rowHeights = ref<number[]>([]); |
| 149 | + const columnWidths = ref<number[]>([]); |
| 150 | + watch(() => props.pageSize, (newRows) => { |
| 151 | + // rows are set to null when new records are loading |
| 152 | + rowHeights.value = newRows || !rowRefs.value ? [] : rowRefs.value.map((el: HTMLElement) => el.offsetHeight); |
| 153 | + columnWidths.value = newRows || !headerRefs.value ? [] : [48, ...headerRefs.value.map((el: HTMLElement) => el.offsetWidth)]; |
| 154 | +}); |
138 | 155 |
|
139 | 156 | const dataResult = asyncComputed( async() => { |
140 | 157 | if (typeof props.data === 'function') { |
|
179 | 196 | // page input should accept only numbers, arrow keys and backspace |
180 | 197 | if (['Enter', 'Space'].includes(event.code) || |
181 | 198 | (!['Backspace', 'ArrowRight', 'ArrowLeft'].includes(event.code) |
182 | | - && isNaN(String.fromCharCode(event.keyCode)))) { |
| 199 | + && isNaN(Number(String.fromCharCode(event.keyCode || 0))))) { |
183 | 200 | event.preventDefault(); |
184 | 201 | if (event.code === 'Enter') { |
185 | 202 | validatePageInput(); |
|
0 commit comments