Skip to content

Commit c2eab2a

Browse files
authored
Merge pull request #2 from BitTheCat/additional-row-header
Additional Row Header (0.1.7)
2 parents 147c334 + c5d8563 commit c2eab2a

File tree

4 files changed

+38
-18
lines changed

4 files changed

+38
-18
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Contains the TVPaginator component that can be disabled via prop or used in stan
66

77
<img src="https://github.com/BitTheCat/tailwind-vue-data-table/blob/main/assets/tvdatatable.jpg"/>
88

9+
<hr>
10+
11+
#### ❗️ *__Documentation soon available__*
12+
##### For now, check under dev/TableShow.vue to see the table in action
13+
14+
<hr>
15+
916
### Install
1017
```
1118
npm i @bitthecat/tailwind-vue-data-table
@@ -43,7 +50,7 @@ import { TVTable } from '@bitthecat/tailwind-vue-data-table'
4350
- Busy state ✔️
4451
<img src="https://github.com/BitTheCat/tailwind-vue-data-table/blob/main/assets/tvtable_busy_state.jpg"/>
4552

46-
- Additional rows up the header
53+
- Additional rows up the header ✔️
4754

4855
- Select rows
4956

@@ -77,7 +84,8 @@ import { TVTable } from '@bitthecat/tailwind-vue-data-table'
7784
| items | table data |
7885
| fields | data fields |
7986
| #cell:FIELD_NAME | used for overwrite |
80-
87+
| #row-details | row details, you need to use row.toggleDetails(row.item) within a template that contains an icon/button to toggle it |
88+
| #header-row | used for additional rows up the header |
8189

8290
slot 'cell:' has item or data props
8391

dev/TableShow.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
@check-row="checkRow"
3131
@row-clicked="checkRow"
3232
>
33+
<template #header-row>
34+
<tr>
35+
<td colspan="2" />
36+
<td colspan="2" class="bg-white text-center">Header1</td>
37+
<td colspan="1" class="bg-red-300 text-center">Header2</td>
38+
</tr>
39+
</template>
40+
3341
<template #cell:username="row">
3442
{{ row.item.emoji }} - {{ row.item.username }}
3543
</template>
@@ -42,10 +50,10 @@
4250
<input id="checkbox" :checked="row.item._showDetails" type="checkbox" @click.stop="row.toggleDetails(row.item)" />
4351
</template>
4452
</TVTable>
45-
Selected:
46-
<pre>
47-
{{ selectRow }}
48-
</pre>
53+
54+
<div class="text-left mt-2">
55+
Selected: {{ selectRow }}
56+
</div>
4957
</div>
5058
</div>
5159
</template>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bitthecat/tailwind-vue-data-table",
3-
"version": "0.1.6",
3+
"version": "0.1.7",
44
"keywords": [
55
"tailwindcss",
66
"vue",

src/components/TVTable.vue

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
<span>Displaying {{ fromRow + 1 }} to {{ toRow }} of {{ totalRows }} items</span>
44
</div>
55

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" />
89
<tr class="divide-x divide-y">
910
<th
1011
v-if="enableCheck"
@@ -64,25 +65,25 @@
6465
</div>
6566
</td>
6667
</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">
6869
<tr
69-
:id="`TV_TABLE_row_${item.label}`"
70+
:id="`TVTABLE_row_${index}_${item.id}`"
7071
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"
7172
:class="index % 2 ? 'bg-gray-300/50' : 'bg-gray-100/50'"
7273
@click="rowClicked(item)"
7374
>
7475
<td
7576
v-if="enableCheck"
7677
: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"
7879
>
7980
<input id="checkbox" v-model="selectedRows" :value="item" type="checkbox" @click.stop="emit('checkRow', item)" />
8081
</td>
8182

8283
<td
8384
v-for="field in fields"
8485
: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"
8687
:class="field.tdClass"
8788
:style="field.tdStyle"
8889
>
@@ -99,10 +100,10 @@
99100
<tr
100101
v-if="item._showDetails"
101102
: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>
106107
</tr>
107108
</template>
108109
</tbody>
@@ -117,13 +118,16 @@
117118
</template>
118119

119120
<script setup>
120-
import {computed, defineComponent, ref, watch} from 'vue';
121+
import {computed, defineComponent, ref, useAttrs, useSlots, watch} from 'vue';
121122
import TVPagination from './TVPagination.vue';
122123
123124
defineComponent({
124125
name: 'TVTable'
125126
})
126127
128+
const slots = useSlots();
129+
const attrs = useAttrs();
130+
127131
const props = defineProps({
128132
items: {
129133
type: [Object, Array],

0 commit comments

Comments
 (0)