-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #460 from icflorescu/next
Implement pinning the last column feature
- Loading branch information
Showing
24 changed files
with
390 additions
and
151 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
98 changes: 98 additions & 0 deletions
98
app/examples/pinning-the-last-column/PinLastColumnExample.tsx
This file contains 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,98 @@ | ||
'use client'; | ||
|
||
import { ActionIcon, Box, Button, Grid, GridCol, Group, Stack, Text } from '@mantine/core'; | ||
import { closeModal, openModal } from '@mantine/modals'; | ||
import { IconEdit, IconEye, IconTrash } from '@tabler/icons-react'; | ||
import { DataTable } from '__PACKAGE__'; | ||
import { employees, type Employee } from '~/data'; | ||
|
||
const records = employees.slice(0, 5); | ||
|
||
const showModal = ({ employee, action }: { employee: Employee; action: 'view' | 'edit' | 'delete' }) => { | ||
openModal({ | ||
modalId: action, | ||
title: | ||
action === 'view' | ||
? 'Showing company information' | ||
: action === 'edit' | ||
? 'Editing company information' | ||
: 'Deleting company', | ||
children: ( | ||
<Stack> | ||
<Text> | ||
{action === 'view' | ||
? 'Here’s where you could show more information...' | ||
: action === 'edit' | ||
? 'Here’s where you could put an edit form...' | ||
: 'Here’s where you could ask for confirmation before deleting...'} | ||
</Text> | ||
<Grid gutter="xs"> | ||
<GridCol span={2}>ID</GridCol> | ||
<GridCol span={10}>{employee.id}</GridCol> | ||
<GridCol span={2}>First name</GridCol> | ||
<GridCol span={10}>{employee.firstName}</GridCol> | ||
<GridCol span={2}>Last name</GridCol> | ||
<GridCol span={10}>{employee.lastName}</GridCol> | ||
</Grid> | ||
<Button onClick={() => closeModal(action)}>Close</Button> | ||
</Stack> | ||
), | ||
}); | ||
}; | ||
|
||
export function PinLastColumnExample() { | ||
// example-start | ||
return ( | ||
<DataTable | ||
pinLastColumn // 👈 make sure the last column is always visible | ||
withTableBorder | ||
columns={[ | ||
{ accessor: 'firstName', noWrap: true }, | ||
{ accessor: 'lastNameName', noWrap: true }, | ||
{ accessor: 'department.name', title: 'Department' }, | ||
{ accessor: 'department.company.name', title: 'Company', noWrap: true }, | ||
{ accessor: 'department.company.city', title: 'City', noWrap: true }, | ||
{ accessor: 'department.company.state', title: 'State' }, | ||
{ accessor: 'department.company.streetAddress', title: 'Address', noWrap: true }, | ||
{ accessor: 'department.company.missionStatement', title: 'Mission statement', noWrap: true }, | ||
{ | ||
accessor: 'actions', | ||
title: <Box mr={6}>Row actions</Box>, | ||
textAlign: 'right', | ||
render: (employee) => ( | ||
// example-skip action cells custom rendering | ||
<Group gap={4} justify="right" wrap="nowrap"> | ||
<ActionIcon | ||
size="sm" | ||
variant="subtle" | ||
color="green" | ||
onClick={() => showModal({ employee, action: 'view' })} | ||
> | ||
<IconEye size={16} /> | ||
</ActionIcon> | ||
<ActionIcon | ||
size="sm" | ||
variant="subtle" | ||
color="blue" | ||
onClick={() => showModal({ employee, action: 'edit' })} | ||
> | ||
<IconEdit size={16} /> | ||
</ActionIcon> | ||
<ActionIcon | ||
size="sm" | ||
variant="subtle" | ||
color="red" | ||
onClick={() => showModal({ employee, action: 'delete' })} | ||
> | ||
<IconTrash size={16} /> | ||
</ActionIcon> | ||
</Group> | ||
// example-resume | ||
), | ||
}, | ||
]} | ||
records={records} | ||
/> | ||
); | ||
// example-end | ||
} |
This file contains 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,49 @@ | ||
import { Code } from '@mantine/core'; | ||
import type { Route } from 'next'; | ||
import { CodeBlock } from '~/components/CodeBlock'; | ||
import { InternalLink } from '~/components/InternalLink'; | ||
import { PageNavigation } from '~/components/PageNavigation'; | ||
import { PageTitle } from '~/components/PageTitle'; | ||
import { Txt } from '~/components/Txt'; | ||
import { readCodeFile } from '~/lib/code'; | ||
import { getRouteMetadata } from '~/lib/utils'; | ||
import { PinLastColumnExample } from './PinLastColumnExample'; | ||
|
||
const PATH: Route = '/examples/pinning-the-last-column'; | ||
|
||
export const metadata = getRouteMetadata(PATH); | ||
|
||
export default async function PinLastColumnExamplePage() { | ||
const code = await readCodeFile<string>(`${PATH}/PinLastColumnExample.tsx`); | ||
|
||
return ( | ||
<> | ||
<PageTitle of={PATH} /> | ||
<Code hidden>fix, fixed, affix, sticky</Code> | ||
<Txt> | ||
You may have noticed that when you are using{' '} | ||
<InternalLink to="/examples/records-selection">row selection</InternalLink> and the table needs to scroll | ||
horizontally, the checkbox column is always visible. This is because the checkbox column is pinned to the left | ||
side of the table. | ||
</Txt> | ||
<Txt> | ||
In the same way, pinning the last column to the right side of the table could be useful when you have a table | ||
with many columns and you want to make sure the last column is always visible, even when the table is scrolled | ||
horizontally. For instance, you could use this feature to ensure that the{' '} | ||
<InternalLink to="/examples/row-actions-cell">row actions</InternalLink> are always visible. | ||
</Txt> | ||
<Txt> | ||
You can achieve this by setting the <Code>pinLastColumn</Code> DataTable prop to <Code>true</Code>: | ||
</Txt> | ||
<PinLastColumnExample /> | ||
<Txt>Here is the code:</Txt> | ||
<CodeBlock code={code} /> | ||
<Txt warning title="Warning"> | ||
Combining this feature with <InternalLink to="/examples/column-grouping">column grouping</InternalLink> may lead | ||
to minor visual artifacts. | ||
</Txt> | ||
<Txt>Head over to the next example to discover more features.</Txt> | ||
<PageNavigation of={PATH} /> | ||
</> | ||
); | ||
} |
2 changes: 2 additions & 0 deletions
2
app/examples/using-with-mantine-contextmenu/RowContextMenuExample.tsx
This file contains 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 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 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.