Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Table): pagination #1476

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/runtime/components/data/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ export default defineComponent({
type: String,
default: 'label'
},
pagination: {
type: Object as PropType<{ pageCount: number, page: number }>,
default: () => ({})
},
sort: {
type: Object as PropType<{ column: string, direction: 'asc' | 'desc' }>,
default: () => ({})
Expand Down Expand Up @@ -191,21 +195,27 @@ export default defineComponent({

const savedSort = { column: sort.value.column, direction: null }

const page = toRef(() => props.pagination?.page ?? 1)
const pageCount = toRef(() => props.pagination?.pageCount ?? props.rows.length)

const start = computed(() => pageCount.value * (page.value - 1))
const end = computed(() => pageCount.value * page.value)

const rows = computed(() => {
if (!sort.value?.column || props.sortMode === 'manual') {
return props.rows
return props.rows.slice(start.value, end.value)
}

const { column, direction } = sort.value

return props.rows.slice().sort((a, b) => {
return props.rows.toSorted((a, b) => {
const aValue = get(a, column)
const bValue = get(b, column)

const sort = columns.value.find((col) => col.key === column)?.sort ?? defaultSort

return sort(aValue, bValue, direction)
})
}).slice(start.value, end.value)
})

const selected = computed({
Expand Down