Skip to content
This repository was archived by the owner on Jun 27, 2024. It is now read-only.

Commit d9c12a7

Browse files
committed
Show 'no results' warning even if there's no pagination
1 parent bc48f01 commit d9c12a7

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

__tests__/Table.spec.js

+32
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mount } from "@vue/test-utils"
22
import Table from "../js/Tailwind2/Table.vue";
33
import expect from 'expect'
4+
import TableWithDataWithoutPagination from "./TableWithDataWithoutPagination.vue";
45

56
describe('Table.vue', () => {
67
it('can enable a search row', () => {
@@ -200,4 +201,35 @@ describe('Table.vue', () => {
200201
expect(updates).toHaveLength(1);
201202
});
202203
});
204+
205+
it('knows when there are no results and there is no pagination', () => {
206+
const component = mount(Table, {
207+
propsData: {
208+
meta: {},
209+
}
210+
});
211+
212+
expect(component.vm.paginationMeta).toEqual({ meta: { total: 0 } });
213+
});
214+
215+
it('knows when there are results while there is no pagination', () => {
216+
const component = mount(TableWithDataWithoutPagination, {
217+
propsData: {
218+
meta: {},
219+
}
220+
});
221+
222+
expect(component.html()).toContain("<td></td>");
223+
expect(component.html()).not.toContain("No results found");
224+
});
225+
226+
it('uses the meta property for pagination', () => {
227+
const component = mount(Table, {
228+
propsData: {
229+
meta: { meta: { total: 1 } },
230+
}
231+
});
232+
233+
expect(component.html()).not.toContain("No results found");
234+
});
203235
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<template>
2+
<Table>
3+
<template #body>
4+
<tr>
5+
<td></td>
6+
</tr>
7+
</template>
8+
</Table>
9+
</template>
10+
11+
<script>
12+
import Table from "../js/Tailwind2/Table.vue";
13+
14+
export default { components: { Table } };
15+
</script>

js/Components/Table.vue

+18
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ export default {
5252
return Object.keys(this.search || {}).length > 0;
5353
},
5454
55+
hasBody() {
56+
return !!this.$slots.body;
57+
},
58+
5559
onlyData() {
5660
if (this.hasFilters || this.hasColumns || this.hasSearchRows) {
5761
return false;
@@ -63,6 +67,20 @@ export default {
6367
6468
return this.search.global ? false : true;
6569
},
70+
71+
paginationMeta() {
72+
if (this.hasBody) {
73+
return this.meta;
74+
}
75+
76+
const hasPagination = 'meta' in this.meta || ('total' in this.meta && 'to' in this.meta && 'from' in this.meta);
77+
78+
if (hasPagination) {
79+
return this.meta;
80+
}
81+
82+
return { meta: { total: 0 } };
83+
}
6684
},
6785
6886
data() {

js/Tailwind2/Table.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ table >>> tr:hover td {
120120
</slot>
121121

122122
<slot name="pagination">
123-
<Pagination :meta="meta" />
123+
<Pagination :meta="paginationMeta" />
124124
</slot>
125125
</TableWrapper>
126126
</slot>

0 commit comments

Comments
 (0)