Skip to content

Commit

Permalink
Merge pull request #555 from icflorescu/next
Browse files Browse the repository at this point in the history
Update dev deps, add scroll row into view example
  • Loading branch information
icflorescu authored Mar 5, 2024
2 parents 44be814 + 5f5b1c7 commit f88f4b0
Show file tree
Hide file tree
Showing 6 changed files with 875 additions and 731 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
The following is a list of notable changes to the Mantine DataTable component.
Minor versions that are not listed in the changelog are bug fixes and small improvements.

## 7.6.1 (2024-03-05)

- Update dev dependencies to ensure compatibility with Mantine 7.6.1 & Next.js 14.1.2

## 7.6.0 (2024-02-28)

- Update dev dependencies to ensure compatibility with Mantine 7.6.0
Expand Down
5 changes: 5 additions & 0 deletions app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export const ROUTES: RouteInfo[] = [
title: 'Scrollable vs. auto-height',
description: `Example: how to make ${PRODUCT_NAME} vertically scrollable`,
},
{
href: '/examples/scrolling-a-row-into-view',
title: 'Scrolling a row into view',
description: `Example: how to scroll a ${PRODUCT_NAME} row into view`,
},
{
href: '/examples/empty-state',
title: 'Empty state',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use client';

import { Button, Grid, GridCol } from '@mantine/core';
import { DataTable } from '__PACKAGE__';
import { employees } from '~/data';

export function ScrollRowIntoViewExample() {
// example-start
const scrollToFirstRow = () => {
document.querySelector('[data-row-index="1"]')?.scrollIntoView(false);
};

const scrollToFirstAlicia = () => {
document.querySelector('[data-row-first-name="Alicia"]')?.scrollIntoView(false);
};

const scrollToLastRow = () => {
document.querySelector(`[data-row-index="${employees.length - 1}"]`)?.scrollIntoView(false);
};

return (
<>
<Grid mb="md">
<GridCol span={{ md: 4, lg: 3 }}>
<Button fullWidth onClick={scrollToFirstRow}>
Scroll to first row
</Button>
</GridCol>
<GridCol span={{ md: 4, lg: 6 }}>
<Button fullWidth onClick={scrollToFirstAlicia}>
Scroll to first “Alicia”
</Button>
</GridCol>
<GridCol span={{ md: 4, lg: 3 }}>
<Button fullWidth onClick={scrollToLastRow}>
Scroll to last row
</Button>
</GridCol>
</Grid>
<DataTable
records={employees}
customRowAttributes={({ firstName }, recordIndex) => ({
'data-row-first-name': firstName,
'data-row-index': recordIndex,
})}
// example-skip more table props
height={500}
withTableBorder
withColumnBorders
striped
columns={[
{ accessor: 'firstName' },
{ accessor: 'lastName' },
{ accessor: 'email' },
{ accessor: 'department.name', title: 'Department' },
{ accessor: 'department.company.name', title: 'Company', noWrap: true },
{ accessor: 'department.company.streetAddress', title: 'Address', noWrap: true },
{ accessor: 'department.company.city', title: 'City' },
{ accessor: 'department.company.state', title: 'State', textAlign: 'right' },
]}
rowColor={({ firstName }, index) =>
index === 0 || index === employees.length - 1 || firstName === 'Alicia' ? 'red' : undefined
}
// example-resume
/>
</>
);
// example-end
}
57 changes: 57 additions & 0 deletions app/examples/scrolling-a-row-into-view/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Code, Text } from '@mantine/core';
import type { Route } from 'next';
import { CodeBlock } from '~/components/CodeBlock';
import { ExternalLink } from '~/components/ExternalLink';
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 { ScrollRowIntoViewExample } from './ScrollRowIntoViewExample';

const PATH: Route = '/examples/scrolling-a-row-into-view';

export const metadata = getRouteMetadata(PATH);

export default async function ScrollableVsAutoHeightExamplePage() {
const code = await readCodeFile<string>(`${PATH}/ScrollRowIntoViewExample.tsx`);

return (
<>
<PageTitle of={PATH} />
<Txt>
One possible way to scroll a specific row into view is to use the{' '}
<InternalLink to="/examples/custom-row-or-cell-attributes">
<Code>customRowAttributes</Code> property
</InternalLink>{' '}
to add a custom <Code>data-*</Code> attribute to the row, and then use{' '}
<ExternalLink to="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector">
<Code>document.querySelector</Code>
</ExternalLink>{' '}
to find the row and call{' '}
<ExternalLink to="https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView">
<Code>scrollIntoView</Code>
</ExternalLink>{' '}
on it.
</Txt>
<ScrollRowIntoViewExample />
<Txt idea title="Keep in mind">
<Text inherit mb="xs">
Due to the fact that the <Code>DataTable</Code> header is fixed, using <Code>scrollIntoView()</Code> with no
arguments, or the equivalent{' '}
<Code style={{ whiteSpace: 'nowrap' }}>{"scrollIntoView({ block: 'start' })"}</Code>, will not work as
expected.
</Text>
<Text inherit>
You should use <Code>scrollIntoView(false)</Code>, or the equivalent{' '}
<Code style={{ whiteSpace: 'nowrap' }}>{"scrollIntoView({ block: 'end' })"}</Code> instead.
</Text>
</Txt>
<Txt>Here is the code:</Txt>
<CodeBlock code={code} />
<Txt>Head over to the next example to discover more features.</Txt>
<PageNavigation of={PATH} />
</>
);
}
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mantine-datatable",
"version": "7.6.0",
"version": "7.6.1",
"description": "The lightweight, dependency-free, dark-theme aware table component for your Mantine UI data-rich applications, featuring asynchronous data loading support, pagination, intuitive Gmail-style additive batch rows selection, column sorting, custom cell data rendering, row expansion, nesting, context menus, and much more",
"keywords": [
"mantine",
Expand Down Expand Up @@ -82,22 +82,22 @@
"@mantine/modals": "^7.6.1",
"@mantine/notifications": "^7.6.1",
"@tabler/icons-react": "^2.47.0",
"@tanstack/react-query": "^5.24.1",
"@tanstack/react-query": "^5.24.8",
"@types/lodash": "^4.14.202",
"@types/node": "^20.11.21",
"@types/react": "^18.2.60",
"@types/node": "^20.11.24",
"@types/react": "^18.2.63",
"@types/react-dom": "^18.2.19",
"@typescript-eslint/eslint-plugin": "^7.1.0",
"@typescript-eslint/parser": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^7.1.1",
"@typescript-eslint/parser": "^7.1.1",
"clsx": "^2.1.0",
"cssnano": "^6.0.5",
"dayjs": "^1.11.10",
"eslint": "^8.57.0",
"eslint-config-next": "^14.1.0",
"eslint-config-next": "^14.1.1",
"eslint-config-prettier": "^9.1.0",
"lodash": "^4.17.21",
"mantine-contextmenu": "^7.6.1",
"next": "14.1.0",
"mantine-contextmenu": "^7.6.2",
"next": "14.1.2",
"postcss": "^8.4.35",
"postcss-cli": "^11.0.0",
"postcss-import": "^16.0.1",
Expand Down
Loading

0 comments on commit f88f4b0

Please sign in to comment.