Skip to content

Commit 2fb3963

Browse files
committed
fix(table): wrong pagination meta on filter
1 parent bee54cd commit 2fb3963

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed

packages/anu-vue/src/components/data-table/ADataTable.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const _tableProps = reactivePick(props, Object.keys(tableProps).filter(k => !['r
3030
3131
const _rows = ref<Record<string, unknown>[]>(typeof props.rows !== 'function' ? props.rows : [])
3232
const serverTotal = ref(0)
33-
const _total = computed(() => typeof props.rows === 'function' ? serverTotal.value : props.rows.length)
33+
const _total = ref(typeof props.rows === 'function' ? serverTotal.value : props.rows.length)
3434
3535
// SECTION Calculate column
3636
/*
@@ -130,6 +130,9 @@ const fetchRows = () => {
130130
: col.name),
131131
)
132132
133+
// Update total
134+
_total.value = filteredRows.value.length
135+
133136
// Sort
134137
const { results: sortedRows } = useSort(
135138
filteredRows,
@@ -238,11 +241,10 @@ const renderHeaderRightSlot = (typeof props.search === 'boolean' && props.search
238241
239242
// 👉 Pagination meta
240243
const paginationMeta = computed(() => {
241-
const from = typeof props.rows === 'function'
242-
? _rows.value.length
243-
: props.rows.length
244-
? (currentPage.value - 1) * currentPageSize.value + 1
245-
: 0
244+
const from = _rows.value.length
245+
? (currentPage.value - 1) * currentPageSize.value + 1
246+
: 0
247+
246248
const to = isLastPage.value
247249
? _total.value
248250
: currentPage.value * currentPageSize.value

packages/anu-vue/test/ATable.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,30 @@ describe('Testing ATable & ADataTable', async () => {
8989
expect(upArrow.exists()).toBe(true)
9090
expect(downArrow.exists()).toBe(true)
9191
})
92+
93+
it('if we filter the rows pagination should show correct information', async () => {
94+
const wrapper = mount(ADataTable, {
95+
props: {
96+
rows: nameList,
97+
pageSize: 5,
98+
search: true,
99+
},
100+
})
101+
102+
const pagination = wrapper.find('.a-data-table-pagination-meta')
103+
const searchInput = wrapper.find('.a-card-typography-wrapper .a-input-input')
104+
105+
// check pagination
106+
expect(pagination?.text()).toBe('1 - 5 of 10')
107+
108+
await searchInput.setValue('name1')
109+
110+
// check pagination
111+
expect(pagination?.text()).toBe('1 - 2 of 2')
112+
113+
await searchInput.setValue('name4')
114+
115+
// check pagination
116+
expect(pagination?.text()).toBe('1 - 1 of 1')
117+
})
92118
})

0 commit comments

Comments
 (0)