|
3 | 3 | <span>Displaying {{ fromRow + 1 }} to {{ toRow }} of {{ totalRows }} items</span> |
4 | 4 | </div> |
5 | 5 |
|
6 | | - <table class="min-w-full"> |
7 | | - <thead class="bg-gray-300 border"> |
| 6 | + <table ref="TVTABLE" class="min-w-full" v-bind="attrs"> |
| 7 | + <thead class="bg-gray-300 border divide-x divide-y"> |
| 8 | + <slot v-if="slots['header-row']" name="header-row" /> |
8 | 9 | <tr class="divide-x divide-y"> |
9 | 10 | <th |
10 | 11 | v-if="enableCheck" |
|
64 | 65 | </div> |
65 | 66 | </td> |
66 | 67 | </tr> |
67 | | - <template v-for="(item, index) in items" v-else :key="item.label"> |
| 68 | + <template v-for="(item, index) in items" v-else :key="item.id"> |
68 | 69 | <tr |
69 | | - :id="`TV_TABLE_row_${item.label}`" |
| 70 | + :id="`TVTABLE_row_${index}_${item.id}`" |
70 | 71 | class="divide-x divide-y last:border-b-0 px-2 py-1.5 text-left text-xs font-medium border hover:bg-gray-400/50" |
71 | 72 | :class="index % 2 ? 'bg-gray-300/50' : 'bg-gray-100/50'" |
72 | 73 | @click="rowClicked(item)" |
73 | 74 | > |
74 | 75 | <td |
75 | 76 | v-if="enableCheck" |
76 | 77 | :key="`check_${item.label}`" |
77 | | - class="px-2 py-1.5 align-top lg:table-cell last:border-b-0" |
| 78 | + class="px-2 py-1.5 align-top table-cell last:border-b-0" |
78 | 79 | > |
79 | 80 | <input id="checkbox" v-model="selectedRows" :value="item" type="checkbox" @click.stop="emit('checkRow', item)" /> |
80 | 81 | </td> |
81 | 82 |
|
82 | 83 | <td |
83 | 84 | v-for="field in fields" |
84 | 85 | :key="field.key" |
85 | | - class="px-2 py-1.5 align-top lg:table-cell last:border-b-0" |
| 86 | + class="px-2 py-1.5 align-top table-cell last:border-b-0" |
86 | 87 | :class="field.tdClass" |
87 | 88 | :style="field.tdStyle" |
88 | 89 | > |
|
99 | 100 | <tr |
100 | 101 | v-if="item._showDetails" |
101 | 102 | :class="index % 2 ? 'bg-gray-300/50' : 'bg-gray-100/50'" |
102 | | - > |
103 | | - <td :colspan="enableCheck ? fields.length + 1 : fields.length"> |
104 | | - <slot name="row-details" :item="item" /> |
105 | | - </td> |
| 103 | + > |
| 104 | + <td :colspan="enableCheck ? fields.length + 1 : fields.length"> |
| 105 | + <slot name="row-details" :item="item" /> |
| 106 | + </td> |
106 | 107 | </tr> |
107 | 108 | </template> |
108 | 109 | </tbody> |
|
117 | 118 | </template> |
118 | 119 |
|
119 | 120 | <script setup> |
120 | | -import {computed, defineComponent, ref, watch} from 'vue'; |
| 121 | +import {computed, defineComponent, ref, useAttrs, useSlots, watch} from 'vue'; |
121 | 122 | import TVPagination from './TVPagination.vue'; |
122 | 123 |
|
123 | 124 | defineComponent({ |
124 | 125 | name: 'TVTable' |
125 | 126 | }) |
126 | 127 |
|
| 128 | +const slots = useSlots(); |
| 129 | +const attrs = useAttrs(); |
| 130 | +
|
127 | 131 | const props = defineProps({ |
128 | 132 | items: { |
129 | 133 | type: [Object, Array], |
|
0 commit comments