Skip to content

Commit 17a353d

Browse files
authored
Merge pull request #6 from BitTheCat/fix/currentPage-add-new-features
TVTable v2
2 parents 6e50565 + 4d467d8 commit 17a353d

File tree

5 files changed

+40
-113
lines changed

5 files changed

+40
-113
lines changed

README.md

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Contains the TVPaginator component that can be disabled via prop or used in stan
99
<hr>
1010

1111
#### ❗️ *__Documentation soon available__*
12-
##### For now, check under dev/TableShow.vue to see the table in action
12+
##### For now, check under dev/TableShow.vue to see the table in action or [here](https://bitthecat.github.io/tailwind-vue-data-table.html)
1313

1414
<hr>
1515

@@ -32,107 +32,6 @@ content: [
3232
import { TVTable } from '@bitthecat/tailwind-vue-data-table'
3333
```
3434

35-
### Next additions
36-
- Pagination (can be disabled) ✔️
37-
38-
<img src="https://github.com/BitTheCat/tailwind-vue-data-table/blob/main/assets/tvpagination.jpg"/>
39-
40-
- Select row column (with checkbox) ✔️
41-
42-
<img src="https://github.com/BitTheCat/tailwind-vue-data-table/blob/main/assets/tvtable_checkbox.jpg"/>
43-
44-
- Row detail ✔️
45-
46-
<img src="https://github.com/BitTheCat/tailwind-vue-data-table/blob/main/assets/tvtable_row_details.jpg"/>
47-
48-
- Row Clicked event ✔️
49-
50-
- Busy state ✔️
51-
<img src="https://github.com/BitTheCat/tailwind-vue-data-table/blob/main/assets/tvtable_busy_state.jpg"/>
52-
53-
- Additional rows up the header ✔️
54-
55-
- Select rows (visual) ✔️
56-
57-
- Footer ✔️
58-
59-
- Provide item from api url
60-
61-
- ...
62-
63-
<hr>
64-
65-
## Table
66-
### Props
67-
68-
| Props | Default | Description |
69-
| --- | --- | --- |
70-
| currentPage | 1 | current displayed page (used by the paginator) |
71-
| totalRows | 0 | total number of rows (used by the paginator) |
72-
| perPage | 15 | number of rows displayed for page (used by the paginator) |
73-
| hidePagination | false | enables for hide paginator |
74-
| multipleSortable | false | enables multiple sortable for table header |
75-
| enableCheck | false | enables checkbox for table row |
76-
| busy | false | enables spinner for loading data |
77-
78-
### Slots
79-
80-
| Props | Description |
81-
| --- | --- |
82-
| items | table data |
83-
| fields | data fields |
84-
| #cell:FIELD_NAME | used for overwrite |
85-
| #row-details | row details, you need to use row.toggleDetails(row.item) within a template that contains an icon/button to toggle it |
86-
| #header-row | used for additional row up the header |
87-
| #footer-row | used for show table footer row |
88-
89-
slot 'cell:' has item or data props
90-
91-
item retrieves the row value
92-
93-
``` html
94-
<template #cell:username="{ item }">
95-
{{ item.emoji }} - {{ item.username }}
96-
</template>
97-
```
98-
99-
data retrieves the field value
100-
101-
``` html
102-
<template #cell:username="{ data }">
103-
{{ data }}
104-
</template>
105-
```
106-
107-
### Events
108-
109-
| Event | Description |
110-
| --- | --- |
111-
| updateSortable | emit the sortable field/fields |
112-
| changePage | emit the page change |
113-
| checkRow | emit the row item when user click on row checkbox |
114-
| rowClicked | emit the row item when user click on row |
115-
116-
##### Notes
117-
118-
##### Any __@click__ event of elements within the row triggers the rowClicked event, to get around this we need to __use @click.stop to prevent the propagation of the event__
119-
120-
<hr>
121-
122-
## Fields
123-
### Props
124-
125-
| Props | Description |
126-
| --- | --- |
127-
| key | th Title |
128-
| label | index of value |
129-
| sortable | the default setting is false, if set to true a symbol appears for sorting |
130-
| thStyle | used for overwrite the th style |
131-
| tdStyle | used for overwrite the td style |
132-
| thClass | used for overwrite the th class |
133-
| tdClass | used for overwrite the td class |
134-
| _showDetails | used for show row details (default false) |
135-
13635
<hr>
13736

13837
This project is licensed under the MIT license. See [LICENSE](LICENSE).

dev/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div class="flex max-w-2xl mx-auto mb-10 space-x-4 sm:mt-10">
44
<div class="flex flex-col flex-grow">
55
<div class="font-semibold mb-2">
6-
Tailwind Vue DataTable
6+
Tailwind Vue DataTable v2
77
<span class="text-xs font-light">by BitTheCat</span>
88
</div>
99
<div>

dev/TableShow.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
:items="cloneItems"
88
:fields="fieldsSimple"
99
:busy="busy"
10+
:body-class="'text-lg'"
11+
:spinner-class="'text-green-500'"
12+
:table-class="'overflow-hidden shadow ring-1 ring-gray-100 md:rounded-lg'"
13+
:head-class="'bg-yellow-600'"
1014
@check-row="checkRow"
1115
@row-clicked="checkRow"
1216
/>
@@ -60,6 +64,7 @@
6064

6165
<div class="text-left mt-2">
6266
Selected: {{ selectRow }}
67+
CurrentPage: {{ currentPage }}
6368
</div>
6469
</div>
6570
</div>

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.8",
3+
"version": "0.2.0",
44
"keywords": [
55
"tailwindcss",
66
"vue",

src/components/TVTable.vue

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

6-
<table ref="TVTABLE" class="min-w-full" v-bind="attrs">
7-
<thead class="bg-gray-300 border divide-x divide-y">
6+
<table ref="TVTABLE" class="min-w-full" :class="tableClass">
7+
<thead class="bg-gray-300 text-xs border divide-x divide-y" :class="headClass">
88
<slot v-if="slots['header-row']" name="header-row" />
99
<tr class="divide-x divide-y">
1010
<th
@@ -16,7 +16,7 @@
1616
<th
1717
v-for="field in fields"
1818
:key="field.label"
19-
class="px-2 py-1.5 text-xs font-medium uppercase"
19+
class="px-2 py-1.5 font-medium uppercase"
2020
:class="field.thClass"
2121
:style="field.thStyle"
2222
>
@@ -52,12 +52,12 @@
5252
</th>
5353
</tr>
5454
</thead>
55-
<tbody class="px-2 py-1.5 text-left text-xs font-medium border">
55+
<tbody class="px-2 py-1.5 text-left text-xs font-medium border" :class="bodyClass">
5656
<tr v-if="busy">
5757
<td :colspan="enableCheck ? fields.length + 1 : fields.length">
5858
<div class="flex justify-center mb-3 mt-3">
5959
<slot name="busy">
60-
<svg class="animate-spin -ml-1 mr-3 h-6 w-6 text-black" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
60+
<svg class="animate-spin -ml-1 mr-3 h-6 w-6 text-black" :class="spinnerClass" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
6161
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
6262
<path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
6363
</svg>
@@ -68,7 +68,7 @@
6868
<template v-for="(item, index) in items" v-else :key="item.id">
6969
<tr
7070
:id="`TVTABLE_row_${index}_${item.id}`"
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+
class="divide-x divide-y last:border-b-0 px-2 py-1.5 text-left font-medium border hover:bg-gray-400/50"
7272
:class="`${index % 2 ? 'bg-gray-300/50' : 'bg-gray-100/50'}`"
7373
@click="rowClicked(item)"
7474
>
@@ -107,7 +107,7 @@
107107
</tr>
108108
</template>
109109
</tbody>
110-
<tfoot class="bg-gray-300 border divide-x divide-y">
110+
<tfoot class="bg-gray-300 border divide-x divide-y" :class="footerClass">
111111
<slot v-if="slots['footer-row']" name="footer-row" />
112112
</tfoot>
113113
</table>
@@ -125,7 +125,8 @@ import {computed, defineComponent, ref, useAttrs, useSlots, watch} from 'vue';
125125
import TVPagination from './TVPagination.vue';
126126
127127
defineComponent({
128-
name: 'TVTable'
128+
name: 'TVTable',
129+
inheritAttrs: false
129130
})
130131
131132
const slots = useSlots();
@@ -152,17 +153,38 @@ const props = defineProps({
152153
type: Number,
153154
default: 15
154155
},
156+
tableClass: {
157+
type: String,
158+
default: ''
159+
},
160+
headClass: {
161+
type: String,
162+
default: ''
163+
},
164+
bodyClass: {
165+
type: String,
166+
default: ''
167+
},
168+
footerClass: {
169+
type: String,
170+
default: ''
171+
},
172+
spinnerClass: {
173+
type: String,
174+
default: ''
175+
},
155176
hidePagination: Boolean,
156177
multipleSortable: Boolean,
157178
enableCheck: Boolean,
158179
busy: Boolean,
159180
})
160181
161182
const emit = defineEmits([
183+
'update:currentPage',
162184
'updateSortable',
163185
'changePage',
164186
'checkRow',
165-
'rowClicked'
187+
'rowClicked',
166188
])
167189
168190
@@ -223,6 +245,7 @@ const checkSelectedForRow = (item) => {
223245
watch(() => localCurrentPage.value, (value) => {
224246
refreshCounter()
225247
emit('changePage', {page: value, from: fromRow.value, to: toRow.value})
248+
emit('update:currentPage', value)
226249
}, {immediate: true})
227250
228251
</script>

0 commit comments

Comments
 (0)