-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(Table): implement row pinning #6115
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
13 commits
Select commit
Hold shift + click to select a range
a407af9
feat(Table): implement row pinning
0xA1337 ecedca5
docs(table): add row pinning section
0xA1337 1817aa8
Merge remote-tracking branch 'upstream/v4' into v4
0xA1337 dfc74eb
Merge branch 'v4' into v4
0xA1337 5422c5c
Merge branch 'v4' into v4
0xA1337 cb33c22
Merge branch 'v4' into v4
0xA1337 99fee06
Merge branch 'v4' into v4
benjamincanac 9c25c8a
fix(Table): disable row pinning when virtualization is enabled
benjamincanac 8276c1a
docs(Table): add row pinning example and fix "binded" typos
benjamincanac 4888c25
chore(playground): add row pinning example to table page
benjamincanac 4892b0d
docs(table): fix hydration issue in row pinning example
benjamincanac 2484ea7
docs(table): improve example
benjamincanac 4d54a32
docs(table): fix highlight
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
151 changes: 151 additions & 0 deletions
151
docs/app/components/content/examples/table/TableRowPinningExample.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,151 @@ | ||
| <script setup lang="ts"> | ||
| import { h, resolveComponent } from 'vue' | ||
| import type { TableColumn } from '@nuxt/ui' | ||
| import type { RowPinningState } from '@tanstack/table-core' | ||
|
|
||
| const UButton = resolveComponent('UButton') | ||
| 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: 'james.anderson@example.com', | ||
| amount: 594 | ||
| }, { | ||
| id: '4599', | ||
| date: '2024-03-11T10:10:00', | ||
| status: 'failed', | ||
| email: 'mia.white@example.com', | ||
| amount: 276 | ||
| }, { | ||
| id: '4598', | ||
| date: '2024-03-11T08:50:00', | ||
| status: 'refunded', | ||
| email: 'william.brown@example.com', | ||
| amount: 315 | ||
| }, { | ||
| id: '4597', | ||
| date: '2024-03-10T19:45:00', | ||
| status: 'paid', | ||
| email: 'emma.davis@example.com', | ||
| amount: 529 | ||
| }, { | ||
| id: '4596', | ||
| date: '2024-03-10T15:55:00', | ||
| status: 'paid', | ||
| email: 'ethan.harris@example.com', | ||
| amount: 639 | ||
| }, { | ||
| id: '4595', | ||
| date: '2024-03-10T13:40:00', | ||
| status: 'refunded', | ||
| email: 'ava.thomas@example.com', | ||
| amount: 428 | ||
| }, { | ||
| id: '4594', | ||
| date: '2024-03-10T09:15:00', | ||
| status: 'paid', | ||
| email: 'michael.wilson@example.com', | ||
| amount: 683 | ||
| }, { | ||
| id: '4593', | ||
| date: '2024-03-09T20:25:00', | ||
| status: 'failed', | ||
| email: 'olivia.taylor@example.com', | ||
| amount: 947 | ||
| }, { | ||
| id: '4592', | ||
| date: '2024-03-09T18:45:00', | ||
| status: 'paid', | ||
| email: 'benjamin.jackson@example.com', | ||
| amount: 851 | ||
| }, { | ||
| id: '4591', | ||
| date: '2024-03-09T16:05:00', | ||
| status: 'paid', | ||
| email: 'sophia.miller@example.com', | ||
| amount: 762 | ||
| }]) | ||
|
|
||
| const columns: TableColumn<Payment>[] = [{ | ||
| id: 'pin', | ||
| cell: ({ row }) => h(UButton, { | ||
| 'icon': 'i-lucide-star', | ||
| 'color': row.getIsPinned() ? 'primary' : 'neutral', | ||
| 'variant': 'ghost', | ||
| 'aria-label': row.getIsPinned() ? 'Unpin row' : 'Pin row to top', | ||
| 'onClick': () => { | ||
| if (row.getIsPinned()) { | ||
| row.pin(false) | ||
| } else { | ||
| row.pin('top') | ||
| } | ||
| } | ||
| }) | ||
| }, { | ||
| 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, | ||
| timeZone: 'UTC' | ||
| }) | ||
| } | ||
| }, { | ||
| 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: 'Amount', | ||
| meta: { | ||
| class: { | ||
| th: 'text-right', | ||
| td: 'text-right font-medium' | ||
| } | ||
| }, | ||
| cell: ({ row }) => { | ||
| const amount = Number.parseFloat(row.getValue('amount')) | ||
| return new Intl.NumberFormat('en-US', { | ||
| style: 'currency', | ||
| currency: 'EUR' | ||
| }).format(amount) | ||
| } | ||
| }] | ||
|
|
||
| const rowPinning = ref<RowPinningState>({ top: ['4599', '4597'], bottom: [] }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <UTable | ||
| v-model:row-pinning="rowPinning" | ||
| :data="data" | ||
| :columns="columns" | ||
| :get-row-id="(row: Payment) => row.id" | ||
| class="flex-1 h-96" | ||
| /> | ||
| </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
Oops, something went wrong.
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.