-
Notifications
You must be signed in to change notification settings - Fork 28
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 #93 from Kuechlin/features-filter-and-selection
Features filter and selection
- Loading branch information
Showing
13 changed files
with
369 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { Stack, Card, Text, Group } from '@mantine/core'; | ||
import { | ||
booleanFilterFn, | ||
DataGrid, | ||
dateFilterFn, | ||
highlightFilterValue, | ||
numberFilterFn, | ||
stringFilterFn, | ||
ExternalColumnFilter, | ||
useDataGrid, | ||
} from '../../../src'; | ||
import CodeDemo from '../../components/CodeDemo'; | ||
import { Data, demoData } from '../../demoData'; | ||
|
||
export default function ExternalFilterExample() { | ||
const [table, setRef] = useDataGrid<Data>(); | ||
|
||
return ( | ||
<CodeDemo code={grid_usage}> | ||
{table && ( | ||
<Group> | ||
<Card> | ||
<Stack> | ||
<Text>Text Filter:</Text> | ||
<ExternalColumnFilter column={table.getColumn('text')} /> | ||
</Stack> | ||
</Card> | ||
</Group> | ||
)} | ||
<DataGrid | ||
data={demoData.splice(0, 25)} | ||
tableRef={setRef} | ||
columns={[ | ||
{ | ||
accessorKey: 'text', | ||
header: 'Text that is too long for a Header', | ||
filterFn: stringFilterFn, | ||
size: 300, | ||
cell: highlightFilterValue, | ||
}, | ||
{ | ||
header: 'Animal', | ||
columns: [ | ||
{ accessorKey: 'cat', filterFn: stringFilterFn }, | ||
{ | ||
accessorKey: 'fish', | ||
filterFn: stringFilterFn, | ||
}, | ||
], | ||
}, | ||
{ | ||
accessorKey: 'city', | ||
filterFn: stringFilterFn, | ||
}, | ||
{ accessorKey: 'value', filterFn: numberFilterFn }, | ||
{ | ||
accessorKey: 'date', | ||
cell: (cell) => cell.getValue<Date>()?.toLocaleDateString(), | ||
filterFn: dateFilterFn, | ||
}, | ||
{ | ||
accessorKey: 'bool', | ||
filterFn: booleanFilterFn, | ||
}, | ||
]} | ||
/> | ||
</CodeDemo> | ||
); | ||
} | ||
const grid_usage = ` | ||
import { | ||
DataGrid, | ||
booleanFilterFn, | ||
dateFilterFn, | ||
highlightFilterValue, | ||
numberFilterFn, | ||
stringFilterFn, | ||
} from 'mantine-data-grid'; | ||
function Demo() { | ||
return ( | ||
<DataGrid | ||
data={data} | ||
striped | ||
highlightOnHover | ||
withGlobalFilter | ||
withPagination | ||
withColumnFilters | ||
withSorting | ||
columns={[ | ||
{ | ||
accessorKey: 'text', | ||
header: 'Text that is too long for a Header', | ||
filterFn: stringFilterFn, | ||
size: 300, | ||
cell: highlightFilterValue, | ||
}, | ||
{ | ||
header: 'Animal', | ||
columns: [ | ||
{ accessorKey: 'cat', filterFn: stringFilterFn }, | ||
{ | ||
accessorKey: 'fish', | ||
filterFn: stringFilterFn, | ||
}, | ||
], | ||
}, | ||
{ | ||
accessorKey: 'city', | ||
filterFn: stringFilterFn, | ||
}, | ||
{ accessorKey: 'value', filterFn: numberFilterFn }, | ||
{ | ||
accessorKey: 'date', | ||
cell: (cell) => | ||
cell.getValue<Date>()?.toLocaleDateString(), | ||
filterFn: dateFilterFn, | ||
}, | ||
{ | ||
accessorKey: 'bool', | ||
filterFn: booleanFilterFn, | ||
}, | ||
]} | ||
/> | ||
); | ||
} | ||
`; |
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,132 @@ | ||
import { RowSelectionState } from '@tanstack/react-table'; | ||
import { useState } from 'react'; | ||
import { | ||
booleanFilterFn, | ||
DataGrid, | ||
dateFilterFn, | ||
highlightFilterValue, | ||
numberFilterFn, | ||
stringFilterFn, | ||
} from '../../../src'; | ||
import CodeDemo from '../../components/CodeDemo'; | ||
import { demoData } from '../../demoData'; | ||
|
||
export default function RowSelectionExample() { | ||
const [selected, setSelected] = useState<RowSelectionState>({}); | ||
return ( | ||
<CodeDemo code={grid_usage}> | ||
<DataGrid | ||
data={demoData} | ||
striped | ||
highlightOnHover | ||
withGlobalFilter | ||
withPagination | ||
withColumnFilters | ||
withSorting | ||
withColumnResizing | ||
withRowSelection | ||
state={{ | ||
rowSelection: selected, | ||
}} | ||
onRowSelectionChange={setSelected} | ||
columns={[ | ||
{ | ||
accessorKey: 'text', | ||
header: 'Text that is too long for a Header', | ||
filterFn: stringFilterFn, | ||
size: 300, | ||
cell: highlightFilterValue, | ||
}, | ||
{ | ||
header: 'Animal', | ||
columns: [ | ||
{ accessorKey: 'cat', filterFn: stringFilterFn }, | ||
{ | ||
accessorKey: 'fish', | ||
filterFn: stringFilterFn, | ||
}, | ||
], | ||
}, | ||
{ | ||
accessorKey: 'city', | ||
filterFn: stringFilterFn, | ||
}, | ||
{ accessorKey: 'value', filterFn: numberFilterFn }, | ||
{ | ||
accessorKey: 'date', | ||
cell: (cell) => cell.getValue<Date>()?.toLocaleDateString(), | ||
filterFn: dateFilterFn, | ||
}, | ||
{ | ||
accessorKey: 'bool', | ||
filterFn: booleanFilterFn, | ||
}, | ||
]} | ||
/> | ||
</CodeDemo> | ||
); | ||
} | ||
const grid_usage = ` | ||
import { | ||
DataGrid, | ||
booleanFilterFn, | ||
dateFilterFn, | ||
highlightFilterValue, | ||
numberFilterFn, | ||
stringFilterFn, | ||
} from 'mantine-data-grid'; | ||
function Demo() { | ||
const [selected, setSelected] = useState<RowSelectionState>({}); | ||
return ( | ||
<DataGrid | ||
data={demoData} | ||
striped | ||
highlightOnHover | ||
withGlobalFilter | ||
withPagination | ||
withColumnFilters | ||
withSorting | ||
withColumnResizing | ||
withRowSelection | ||
state={{ | ||
rowSelection: selected, | ||
}} | ||
onRowSelectionChange={setSelected} | ||
columns={[ | ||
{ | ||
accessorKey: 'text', | ||
header: 'Text that is too long for a Header', | ||
filterFn: stringFilterFn, | ||
size: 300, | ||
cell: highlightFilterValue, | ||
}, | ||
{ | ||
header: 'Animal', | ||
columns: [ | ||
{ accessorKey: 'cat', filterFn: stringFilterFn }, | ||
{ | ||
accessorKey: 'fish', | ||
filterFn: stringFilterFn, | ||
}, | ||
], | ||
}, | ||
{ | ||
accessorKey: 'city', | ||
filterFn: stringFilterFn, | ||
}, | ||
{ accessorKey: 'value', filterFn: numberFilterFn }, | ||
{ | ||
accessorKey: 'date', | ||
cell: (cell) => cell.getValue<Date>()?.toLocaleDateString(), | ||
filterFn: dateFilterFn, | ||
}, | ||
{ | ||
accessorKey: 'bool', | ||
filterFn: booleanFilterFn, | ||
}, | ||
]} | ||
/> | ||
); | ||
} | ||
`; |
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.