-
-
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 #10 from icflorescu/next
Backport column dragging, toggling, resizing from V7
- Loading branch information
Showing
26 changed files
with
1,906 additions
and
719 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,27 @@ | ||
import { DataTable, useDataTableColumns } from 'mantine-datatable'; | ||
import { companies, type Company } from '~/data'; | ||
|
||
import { Button, Group, Stack } from '@mantine/core'; | ||
|
||
export default function DraggingExample() { | ||
const key = 'draggable-example'; | ||
|
||
const { effectiveColumns, resetColumnsOrder } = useDataTableColumns<Company>({ | ||
key, | ||
columns: [ | ||
{ accessor: 'name', width: '40%', draggable: true }, | ||
{ accessor: 'streetAddress', width: '60%', draggable: true }, | ||
{ accessor: 'city', width: 160, ellipsis: true, draggable: true }, | ||
{ accessor: 'state' }, | ||
], | ||
}); | ||
|
||
return ( | ||
<Stack> | ||
<DataTable withBorder withColumnBorders storeColumnsKey={key} records={companies} columns={effectiveColumns} /> | ||
<Group position="right"> | ||
<Button onClick={resetColumnsOrder}>Reset Column Order</Button> | ||
</Group> | ||
</Stack> | ||
); | ||
} |
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,57 @@ | ||
import { IconColumnRemove, IconColumns1 } from '@tabler/icons-react'; | ||
import sortBy from 'lodash/sortBy'; | ||
import { DataTable, DataTableSortStatus, useDataTableColumns } from 'mantine-datatable'; | ||
import { useEffect, useState } from 'react'; | ||
import { companies, type Company } from '~/data'; | ||
|
||
export default function DraggingTogglingComplexExample() { | ||
const key = 'draggable-toggleable-complex-example'; | ||
|
||
const [sortStatus, setSortStatus] = useState<DataTableSortStatus>({ | ||
columnAccessor: 'name', | ||
direction: 'asc', | ||
}); | ||
|
||
const [records, setRecords] = useState(sortBy(companies, 'name')); | ||
|
||
useEffect(() => { | ||
const data = sortBy(companies, sortStatus.columnAccessor) as Company[]; | ||
setRecords(sortStatus.direction === 'desc' ? data.reverse() : data); | ||
}, [sortStatus]); | ||
|
||
const { effectiveColumns, resetColumnsOrder, resetColumnsToggle } = useDataTableColumns({ | ||
key, | ||
columns: [ | ||
{ accessor: 'name', width: '40%', toggleable: true, draggable: true, sortable: true }, | ||
{ accessor: 'streetAddress', width: '60%', toggleable: true, draggable: true }, | ||
{ accessor: 'city', width: 160, ellipsis: true, toggleable: true, draggable: true }, | ||
{ accessor: 'state' }, | ||
], | ||
}); | ||
|
||
return ( | ||
<DataTable | ||
withBorder | ||
withColumnBorders | ||
storeColumnsKey={key} | ||
records={records} | ||
columns={effectiveColumns} | ||
sortStatus={sortStatus} | ||
onSortStatusChange={setSortStatus} | ||
rowContextMenu={{ | ||
items: () => [ | ||
{ | ||
key: 'reset-columns.toggled', | ||
icon: <IconColumnRemove size={16} />, | ||
onClick: resetColumnsToggle, | ||
}, | ||
{ | ||
key: 'reset-columns-order', | ||
icon: <IconColumns1 size={16} />, | ||
onClick: resetColumnsOrder, | ||
}, | ||
], | ||
}} | ||
/> | ||
); | ||
} |
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,41 @@ | ||
import { IconColumnRemove, IconColumns1 } from '@tabler/icons-react'; | ||
import { DataTable, useDataTableColumns } from 'mantine-datatable'; | ||
import { companies } from '~/data'; | ||
|
||
export default function DraggingTogglingResetExample() { | ||
const key = 'toggleable-reset-example'; | ||
|
||
const { effectiveColumns, resetColumnsOrder, resetColumnsToggle } = useDataTableColumns({ | ||
key, | ||
columns: [ | ||
{ accessor: 'name', width: '40%', toggleable: true, draggable: true }, | ||
{ accessor: 'streetAddress', width: '60%', toggleable: true, draggable: true }, | ||
{ accessor: 'city', width: 160, ellipsis: true, toggleable: true, draggable: true }, | ||
{ accessor: 'state' }, | ||
], | ||
}); | ||
|
||
return ( | ||
<DataTable | ||
withBorder | ||
withColumnBorders | ||
storeColumnsKey={key} | ||
records={companies} | ||
columns={effectiveColumns} | ||
rowContextMenu={{ | ||
items: () => [ | ||
{ | ||
key: 'reset-columns.toggled', | ||
icon: <IconColumnRemove size={16} />, | ||
onClick: resetColumnsToggle, | ||
}, | ||
{ | ||
key: 'reset-columns-order', | ||
icon: <IconColumns1 size={16} />, | ||
onClick: resetColumnsOrder, | ||
}, | ||
], | ||
}} | ||
/> | ||
); | ||
} |
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,83 @@ | ||
import { Button, Group, Stack, Switch } from '@mantine/core'; | ||
import { sortBy } from 'lodash'; | ||
import { DataTable, DataTableSortStatus, useDataTableColumns } from 'mantine-datatable'; | ||
import { useEffect, useState } from 'react'; | ||
import { companies, type Company } from '~/data'; | ||
|
||
export default function ResizingComplexExample() { | ||
const key = 'resize-complex-example'; | ||
|
||
const [withTableBorder, setWithTableBorder] = useState<boolean>(true); | ||
|
||
const [withColumnBorders, setWithColumnBorders] = useState<boolean>(true); | ||
|
||
const props = { | ||
resizable: true, | ||
sortable: true, | ||
toggleable: true, | ||
draggable: true, | ||
}; | ||
|
||
const { effectiveColumns, resetColumnsWidth, resetColumnsOrder, resetColumnsToggle } = useDataTableColumns<Company>({ | ||
key, | ||
columns: [ | ||
{ accessor: 'name', ...props }, | ||
{ accessor: 'streetAddress', ...props }, | ||
{ accessor: 'city', ...props }, | ||
{ accessor: 'state', ...props }, | ||
], | ||
}); | ||
|
||
const [sortStatus, setSortStatus] = useState<DataTableSortStatus>({ | ||
columnAccessor: 'name', | ||
direction: 'asc', | ||
}); | ||
|
||
const [records, setRecords] = useState(sortBy(companies, 'name')); | ||
|
||
useEffect(() => { | ||
const data = sortBy(companies, sortStatus.columnAccessor) as Company[]; | ||
setRecords(sortStatus.direction === 'desc' ? data.reverse() : data); | ||
}, [sortStatus]); | ||
|
||
return ( | ||
<Stack> | ||
<DataTable | ||
withBorder={withTableBorder} | ||
withColumnBorders={withColumnBorders} | ||
storeColumnsKey={key} | ||
records={records} | ||
columns={effectiveColumns} | ||
sortStatus={sortStatus} | ||
onSortStatusChange={setSortStatus} | ||
/> | ||
<Group grow position="apart"> | ||
<Group position="left"> | ||
<Switch | ||
checked={withTableBorder} | ||
onChange={(event) => setWithTableBorder(event.currentTarget.checked)} | ||
labelPosition="left" | ||
label="Table Border" | ||
/> | ||
<Switch | ||
checked={withColumnBorders} | ||
onChange={(event) => setWithColumnBorders(event.currentTarget.checked)} | ||
labelPosition="left" | ||
label="Column Borders" | ||
/> | ||
</Group> | ||
<Group position="right"> | ||
<Button size="xs" compact onClick={resetColumnsWidth}> | ||
Reset Column Width | ||
</Button> | ||
<Button size="xs" compact onClick={resetColumnsOrder}> | ||
Reset Column Order | ||
</Button> | ||
<Button size="xs" compact onClick={resetColumnsToggle}> | ||
Reset Column Toggle | ||
</Button> | ||
</Group> | ||
</Group> | ||
</Stack> | ||
); | ||
} |
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,52 @@ | ||
import { Button, Group, Stack, Switch } from '@mantine/core'; | ||
import { DataTable, useDataTableColumns } from 'mantine-datatable'; | ||
import { useState } from 'react'; | ||
import { companies, type Company } from '~/data'; | ||
|
||
export default function ResizingExample() { | ||
const key = 'resize-example'; | ||
|
||
const [withTableBorder, setWithTableBorder] = useState<boolean>(true); | ||
const [withColumnBorders, setWithColumnBorders] = useState<boolean>(true); | ||
|
||
const { effectiveColumns, resetColumnsWidth } = useDataTableColumns<Company>({ | ||
key, | ||
columns: [ | ||
{ accessor: 'name', width: 100, resizable: true }, | ||
{ accessor: 'streetAddress', resizable: true }, | ||
{ accessor: 'city', resizable: true }, | ||
{ accessor: 'state' }, | ||
], | ||
}); | ||
|
||
return ( | ||
<Stack> | ||
<DataTable | ||
withBorder={withTableBorder} | ||
withColumnBorders={withColumnBorders} | ||
storeColumnsKey={key} | ||
records={companies} | ||
columns={effectiveColumns} | ||
/> | ||
<Group grow position="apart"> | ||
<Group position="left"> | ||
<Switch | ||
checked={withTableBorder} | ||
onChange={(event) => setWithTableBorder(event.currentTarget.checked)} | ||
labelPosition="left" | ||
label="Table Border" | ||
/> | ||
<Switch | ||
checked={withColumnBorders} | ||
onChange={(event) => setWithColumnBorders(event.currentTarget.checked)} | ||
labelPosition="left" | ||
label="Column Borders" | ||
/> | ||
</Group> | ||
<Group position="right"> | ||
<Button onClick={resetColumnsWidth}>Reset Column Width</Button> | ||
</Group> | ||
</Group> | ||
</Stack> | ||
); | ||
} |
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,26 @@ | ||
import { Button, Group, Stack } from '@mantine/core'; | ||
import { DataTable, useDataTableColumns } from 'mantine-datatable'; | ||
import { companies } from '~/data'; | ||
|
||
export default function TogglingExample() { | ||
const key = 'toggleable-example'; | ||
|
||
const { effectiveColumns, resetColumnsToggle } = useDataTableColumns({ | ||
key, | ||
columns: [ | ||
{ accessor: 'name', width: '40%', toggleable: true }, | ||
{ accessor: 'streetAddress', width: '60%', toggleable: true }, | ||
{ accessor: 'city', width: 160, toggleable: true }, | ||
{ accessor: 'state' }, | ||
], | ||
}); | ||
|
||
return ( | ||
<Stack> | ||
<DataTable withBorder withColumnBorders storeColumnsKey={key} records={companies} columns={effectiveColumns} /> | ||
<Group position="right"> | ||
<Button onClick={resetColumnsToggle}>Reset Column Toggled</Button> | ||
</Group> | ||
</Stack> | ||
); | ||
} |
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.