mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-01-26 09:50:33 +01:00
feat(Table): add footer support to display column summary (#4194)
Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
@@ -4,7 +4,7 @@ import { flushPromises } from '@vue/test-utils'
|
||||
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
||||
import { UCheckbox, UButton, UBadge, UDropdownMenu } from '#components'
|
||||
import Table from '../../src/runtime/components/Table.vue'
|
||||
import type { TableProps, TableSlots, TableColumn } from '../../src/runtime/components/Table.vue'
|
||||
import type { TableProps, TableSlots, TableColumn, TableRow } from '../../src/runtime/components/Table.vue'
|
||||
import ComponentRender from '../component-render'
|
||||
import theme from '#build/ui/table'
|
||||
|
||||
@@ -99,6 +99,16 @@ describe('Table', () => {
|
||||
}, {
|
||||
accessorKey: 'amount',
|
||||
header: () => h('div', { class: 'text-right' }, 'Amount'),
|
||||
footer: ({ column }) => {
|
||||
const total = column.getFacetedRowModel().rows.reduce((acc: number, row: TableRow<typeof data[number]>) => acc + Number.parseFloat(row.getValue('amount')), 0)
|
||||
|
||||
const formatted = new Intl.NumberFormat('en-US', {
|
||||
style: 'currency',
|
||||
currency: 'EUR'
|
||||
}).format(total)
|
||||
|
||||
return h('div', { class: 'text-right font-medium' }, `Total: ${formatted}`)
|
||||
},
|
||||
cell: ({ row }) => {
|
||||
const amount = Number.parseFloat(row.getValue('amount'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user