-
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #7 from icflorescu/next
Backport pinning the last column feature
- Loading branch information
Showing
13 changed files
with
276 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { ActionIcon, Box, Button, Grid, Group, Stack, Text } from '@mantine/core'; | ||
import { closeModal, openModal } from '@mantine/modals'; | ||
import { IconEdit, IconEye, IconTrash } from '@tabler/icons-react'; | ||
import { DataTable } from 'mantine-datatable'; | ||
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"> | ||
<Grid.Col span={2}>ID</Grid.Col> | ||
<Grid.Col span={10}>{employee.id}</Grid.Col> | ||
<Grid.Col span={2}>First name</Grid.Col> | ||
<Grid.Col span={10}>{employee.firstName}</Grid.Col> | ||
<Grid.Col span={2}>Last name</Grid.Col> | ||
<Grid.Col span={10}>{employee.lastName}</Grid.Col> | ||
</Grid> | ||
<Button onClick={() => closeModal(action)}>Close</Button> | ||
</Stack> | ||
), | ||
}); | ||
}; | ||
|
||
export default function PinLastColumnExample() { | ||
// example-start | ||
return ( | ||
<DataTable | ||
pinLastColumn // 👈 make sure the last column is always visible | ||
withBorder | ||
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>, | ||
textAlignment: 'right', | ||
render: (employee) => ( | ||
// example-skip action cells custom rendering | ||
<Group spacing={4} noWrap position="right"> | ||
<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
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, Container } from '@mantine/core'; | ||
import { GetStaticProps, InferGetStaticPropsType } from 'next'; | ||
import CodeBlock from '~/components/CodeBlock'; | ||
import InternalLink from '~/components/InternalLink'; | ||
import PageNavigation from '~/components/PageNavigation'; | ||
import PageText from '~/components/PageText'; | ||
import PageTitle from '~/components/PageTitle'; | ||
import PinLastColumnExample from '~/examples/PinLastColumnExample'; | ||
import readCodeExample from '~/lib/readCodeExample'; | ||
|
||
const PATH = 'examples/pinning-the-last-column'; | ||
|
||
export const getStaticProps: GetStaticProps<{ | ||
code: string; | ||
}> = async () => ({ | ||
props: { code: (await readCodeExample('examples/PinLastColumnExample.tsx')) as string }, | ||
}); | ||
|
||
export default function Page({ code }: InferGetStaticPropsType<typeof getStaticProps>) { | ||
return ( | ||
<Container> | ||
<PageTitle of={PATH} /> | ||
<PageText> | ||
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. | ||
</PageText> | ||
<PageText> | ||
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. | ||
</PageText> | ||
<PageText> | ||
You can achieve this by setting the <Code>pinLastColumn</Code> DataTable prop to <Code>true</Code>: | ||
</PageText> | ||
<PinLastColumnExample /> | ||
<PageText>Here is the code:</PageText> | ||
<CodeBlock language="typescript" content={code} /> | ||
<PageText warning> | ||
Combining this feature with <InternalLink to="/examples/column-grouping">column grouping</InternalLink> may lead | ||
to minor visual artifacts. | ||
</PageText> | ||
<PageText>Head over to the next example to discover more features.</PageText> | ||
<PageNavigation of={PATH} /> | ||
</Container> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.