Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(resizable): set a controlled width for resizable columns #374

Merged
merged 1 commit into from
Nov 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions docs/examples/CustomColumnTable.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ const App = () => {
});
}, []);

const [columnWidths, setColumnWidths] = React.useState({
id: 80,
firstName: 150,
lastName: 150,
email: 300
});

const handleColumnResize = (columnWidth, dataKey) => {
setColumnWidths(prevColumnWidths => {
const nextColumnWidths = { ...prevColumnWidths };
nextColumnWidths[dataKey] = columnWidth;
return nextColumnWidths;
});
};

return (
<Table height={400} data={data} headerHeight={50} virtualized>
<Column width={50} align="center">
Expand All @@ -130,22 +145,22 @@ const App = () => {
</HeaderCell>
<CheckCell dataKey="id" checkedKeys={checkedKeys} onChange={handleCheck} />
</Column>
<Column width={80} align="center">
<Column width={columnWidths.id} align="center" resizable onResize={handleColumnResize}>
<HeaderCell>Id</HeaderCell>
<NameCell dataKey="id" />
<Cell dataKey="id" />
</Column>
<Column width={160}>
<Column width={columnWidths.firstName} resizable onResize={handleColumnResize}>
<HeaderCell>First Name</HeaderCell>
<NameCell dataKey="firstName" />
</Column>
<Column width={160}>
<Column width={columnWidths.lastName} resizable onResize={handleColumnResize}>
<HeaderCell>Last Name</HeaderCell>
<BaseCell dataKey="lastName" />
</Column>

<Column width={300}>
<Column width={columnWidths.email} resizable onResize={handleColumnResize}>
<HeaderCell>Email</HeaderCell>
<InputCell data={emailList} onChange={handleEmailChange} />
<InputCell dataKey="email" data={emailList} onChange={handleEmailChange} />
</Column>

<Column width={200}>
Expand Down