|
52 | 52 | </tr> |
53 | 53 | </thead> |
54 | 54 | <tbody class="px-2 py-1.5 text-left text-xs font-medium border"> |
55 | | - <tr |
56 | | - v-for="(item) in items" |
57 | | - :key="item.label" |
58 | | - class="divide-x divide-y last:border-b-0 px-2 py-1.5 text-left text-xs font-medium border odd:bg-gray-300/50 even:bg-gray-100/50 hover:bg-gray-400/50" |
59 | | - > |
60 | | - <td |
61 | | - v-if="enableCheck" |
62 | | - :key="`check_${item.label}`" |
63 | | - class="px-2 py-1.5 align-top lg:table-cell last:border-b-0" |
| 55 | + <template v-for="(item) in items" :key="item.label"> |
| 56 | + <tr |
| 57 | + class="divide-x divide-y last:border-b-0 px-2 py-1.5 text-left text-xs font-medium border odd:bg-gray-300/50 even:bg-gray-100/50 hover:bg-gray-400/50" |
64 | 58 | > |
65 | | - <input id="checkbox" v-model="selectedRow" :value="item" type="checkbox" @change="emit('checkRow', item)" /> |
66 | | - </td> |
| 59 | + <td |
| 60 | + v-if="enableCheck" |
| 61 | + :key="`check_${item.label}`" |
| 62 | + class="px-2 py-1.5 align-top lg:table-cell last:border-b-0" |
| 63 | + > |
| 64 | + <input id="checkbox" v-model="selectedRow" :value="item" type="checkbox" @change="emit('checkRow', item)" /> |
| 65 | + </td> |
67 | 66 |
|
68 | | - <td |
69 | | - v-for="field in fields" |
70 | | - :key="field.key" |
71 | | - class="px-2 py-1.5 align-top lg:table-cell last:border-b-0" |
72 | | - :class="field.tdClass" |
73 | | - :style="field.tdStyle" |
74 | | - > |
75 | | - <slot :item="item" :data="getField(item, field.key)" :name="`cell:${field.label}`"> |
76 | | - {{ getField(item, field.key) }} |
77 | | - </slot> |
78 | | - </td> |
79 | | - </tr> |
| 67 | + <td |
| 68 | + v-for="field in fields" |
| 69 | + :key="field.key" |
| 70 | + class="px-2 py-1.5 align-top lg:table-cell last:border-b-0" |
| 71 | + :class="field.tdClass" |
| 72 | + :style="field.tdStyle" |
| 73 | + > |
| 74 | + <slot |
| 75 | + :name="`cell:${field.label}`" |
| 76 | + :item="item" |
| 77 | + :data="getField(item, field.key)" |
| 78 | + :toggle-details="toggleDetails" |
| 79 | + > |
| 80 | + {{ getField(item, field.key, '') }} |
| 81 | + </slot> |
| 82 | + </td> |
| 83 | + </tr> |
| 84 | + <tr v-if="item._showDetails"> |
| 85 | + <td :colspan="enableCheck ? fields.length + 1 : fields.length"> |
| 86 | + <slot name="row-details" :item="item" /> |
| 87 | + </td> |
| 88 | + </tr> |
| 89 | + </template> |
80 | 90 | </tbody> |
81 | 91 | </table> |
82 | 92 |
|
|
89 | 99 | </template> |
90 | 100 |
|
91 | 101 | <script setup> |
92 | | -import {defineComponent, ref, watch} from 'vue'; |
| 102 | +import {computed, defineComponent, ref, watch} from 'vue'; |
93 | 103 | import TVPagination from './TVPagination.vue'; |
94 | 104 |
|
95 | 105 | defineComponent({ |
@@ -124,13 +134,21 @@ const props = defineProps({ |
124 | 134 |
|
125 | 135 | const emit = defineEmits(['updateSortable', 'changePage', 'checkRow']) |
126 | 136 |
|
127 | | -const localTotalRows = ref(props.totalRows || props.items.length || 0) |
| 137 | +
|
| 138 | +const localTotalRows = computed(() => { |
| 139 | + return props.totalRows || props.items.length || 0 |
| 140 | +}) |
| 141 | +
|
128 | 142 | const fromRow = ref(0) |
129 | 143 | const toRow = ref(0) |
130 | 144 | const localCurrentPage = ref(props.currentPage) |
131 | 145 |
|
132 | | -const getField = (item, field) => { |
133 | | - return item[field] |
| 146 | +const getField = (item, field, def) => { |
| 147 | + return item[field] || def |
| 148 | +} |
| 149 | +
|
| 150 | +const toggleDetails = (value) => { |
| 151 | + return value._showDetails = !value._showDetails |
134 | 152 | } |
135 | 153 |
|
136 | 154 | const sortable = ref({}) |
|
0 commit comments