-
Notifications
You must be signed in to change notification settings - Fork 794
feat(Table): add footer
support to display column summary
#4194
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2e7f61f
Table footer support
gigor 69a7e95
Merge branch 'nuxt:v3' into v3
gigor 5e70307
Update Table.vue
gigor 0b342f1
Merge branch 'v3' of https://github.com/gigor/ui into v3
gigor 5bee32e
Update Table.spec.ts.snap
gigor b34b78c
Update Table-vue.spec.ts.snap
gigor 38928c8
Drop console log
gigor 2d1b670
Merge branch 'nuxt:v3' into v3
gigor 918d25d
Merge branch 'nuxt:v3' into v3
gigor 2c22061
join sticky & stickyFooter props
gigor 9a4281d
Merge branch 'v3' of https://github.com/gigor/ui into v3
gigor 5143846
Merge branch 'nuxt:v3' into v3
gigor 6f70bd4
Update table.md
gigor 9ce2af8
Merge branch 'nuxt:v3' into v3
gigor 60524aa
Merge branch 'v3' into v3
benjamincanac e88083b
Merge branch 'v3' into pr/4194
benjamincanac 052bf64
up
benjamincanac 86a5ff3
Merge branch 'v3' into v3
benjamincanac 6d9998b
up
benjamincanac 192c3fb
up
benjamincanac ba180a1
add docs example
benjamincanac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
docs/app/components/content/examples/table/TableColumnFooterExample.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<script setup lang="ts"> | ||
import { h, resolveComponent } from 'vue' | ||
import type { TableColumn, TableRow } from '@nuxt/ui' | ||
|
||
const UBadge = resolveComponent('UBadge') | ||
|
||
type Payment = { | ||
id: string | ||
date: string | ||
status: 'paid' | 'failed' | 'refunded' | ||
email: string | ||
amount: number | ||
} | ||
|
||
const data = ref<Payment[]>([{ | ||
id: '4600', | ||
date: '2024-03-11T15:30:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 594 | ||
}, { | ||
id: '4599', | ||
date: '2024-03-11T10:10:00', | ||
status: 'failed', | ||
email: '[email protected]', | ||
amount: 276 | ||
}, { | ||
id: '4598', | ||
date: '2024-03-11T08:50:00', | ||
status: 'refunded', | ||
email: '[email protected]', | ||
amount: 315 | ||
}, { | ||
id: '4597', | ||
date: '2024-03-10T19:45:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 529 | ||
}, { | ||
id: '4596', | ||
date: '2024-03-10T15:55:00', | ||
status: 'paid', | ||
email: '[email protected]', | ||
amount: 639 | ||
}]) | ||
|
||
const columns: TableColumn<Payment>[] = [{ | ||
accessorKey: 'id', | ||
header: '#', | ||
cell: ({ row }) => `#${row.getValue('id')}` | ||
}, { | ||
accessorKey: 'date', | ||
header: 'Date', | ||
cell: ({ row }) => { | ||
return new Date(row.getValue('date')).toLocaleString('en-US', { | ||
day: 'numeric', | ||
month: 'short', | ||
hour: '2-digit', | ||
minute: '2-digit', | ||
hour12: false | ||
}) | ||
} | ||
}, { | ||
accessorKey: 'status', | ||
header: 'Status', | ||
cell: ({ row }) => { | ||
const color = ({ | ||
paid: 'success' as const, | ||
failed: 'error' as const, | ||
refunded: 'neutral' as const | ||
})[row.getValue('status') as string] | ||
|
||
return h(UBadge, { class: 'capitalize', variant: 'subtle', color }, () => row.getValue('status')) | ||
} | ||
}, { | ||
accessorKey: 'email', | ||
header: 'Email' | ||
}, { | ||
accessorKey: 'amount', | ||
header: () => h('div', { class: 'text-right' }, 'Amount'), | ||
footer: ({ column }) => { | ||
const total = column.getFacetedRowModel().rows.reduce((acc: number, row: TableRow<Payment>) => 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')) | ||
|
||
const formatted = new Intl.NumberFormat('en-US', { | ||
style: 'currency', | ||
currency: 'EUR' | ||
}).format(amount) | ||
|
||
return h('div', { class: 'text-right font-medium' }, formatted) | ||
} | ||
}] | ||
</script> | ||
|
||
<template> | ||
<UTable :data="data" :columns="columns" class="flex-1" /> | ||
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.