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

Modify TreeDataGrid to use column.frozen value if present #3417

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/TreeDataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function TreeDataGrid<R, SR, K extends Key>(
groupBy.push(column.key);
columns[index] = {
...column,
frozen: true,
frozen: column.frozen ?? true,
renderCell: () => null,
renderGroupCell: column.renderGroupCell ?? renderToggleGroup,
editable: false
Expand Down
22 changes: 21 additions & 1 deletion website/demos/RowGrouping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const optionsClassname = css`
text-transform: capitalize;
`;

const hrClassname = css`
margin: 0;
`;

interface Row {
id: number;
country: string;
Expand Down Expand Up @@ -169,6 +173,8 @@ export default function RowGrouping({ direction }: Props) {
setExpandedGroupIds(new Set());
}

const [areGroupColumnsFrozen, setAreGroupColumnsFrozen] = useState<boolean>(true);

return (
<div className={groupingClassname}>
<b>Group by columns:</b>
Expand All @@ -185,8 +191,22 @@ export default function RowGrouping({ direction }: Props) {
))}
</div>

<hr className={hrClassname} />

<label>
<input
type="checkbox"
checked={areGroupColumnsFrozen}
onChange={() => setAreGroupColumnsFrozen(!areGroupColumnsFrozen)}
/>{' '}
Frozen group columns
</label>

<TreeDataGrid
columns={columns}
columns={columns.map((c) => ({
...c,
...(selectedOptions.includes(c.key) ? { frozen: areGroupColumnsFrozen } : {})
}))}
rows={rows}
rowKeyGetter={rowKeyGetter}
selectedRows={selectedRows}
Expand Down