Skip to content

Commit

Permalink
feat: Add selectable option to grid
Browse files Browse the repository at this point in the history
  • Loading branch information
matttdawson authored Oct 26, 2022
1 parent 22f1365 commit f0d8bae
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
34 changes: 19 additions & 15 deletions src/components/Grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface GridBaseRow {
}

export interface GridProps {
selectable?: boolean;
dataTestId?: string;
quickFilter?: boolean;
quickFilterPlaceholder?: string;
Expand Down Expand Up @@ -111,21 +112,24 @@ export const Grid = (params: GridProps): JSX.Element => {
}, [synchroniseExternallySelectedItemsToGrid]);

const columnDefs = useMemo(
(): GridOptions["columnDefs"] => [
{
colId: "selection",
editable: false,
initialWidth: 35,
minWidth: 35,
maxWidth: 35,
suppressSizeToFit: true,
checkboxSelection: true,
headerComponent: GridHeaderSelect,
onCellClicked: clickSelectorCheckboxWhenContainingCellClicked,
},
...(params.columnDefs as ColDef[]),
],
[clickSelectorCheckboxWhenContainingCellClicked, params.columnDefs],
(): GridOptions["columnDefs"] =>
params.selectable
? [
{
colId: "selection",
editable: false,
initialWidth: 35,
minWidth: 35,
maxWidth: 35,
suppressSizeToFit: true,
checkboxSelection: true,
headerComponent: GridHeaderSelect,
onCellClicked: clickSelectorCheckboxWhenContainingCellClicked,
},
...(params.columnDefs as ColDef[]),
]
: [...(params.columnDefs as ColDef[])],
[clickSelectorCheckboxWhenContainingCellClicked, params.columnDefs, params.selectable],
);

const onGridReady = useCallback(
Expand Down
1 change: 1 addition & 0 deletions src/stories/components/GridPopoutBearing.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
return (
<Grid
{...props}
selectable={true}
externalSelectedItems={externalSelectedItems}
setExternalSelectedItems={setExternalSelectedItems}
columnDefs={columnDefs}
Expand Down
1 change: 1 addition & 0 deletions src/stories/components/GridPopoutEditDropDown.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const GridEditDropDownTemplate: ComponentStory<typeof Grid> = (props: GridProps)
return (
<Grid
{...props}
selectable={true}
externalSelectedItems={externalSelectedItems}
setExternalSelectedItems={setExternalSelectedItems}
columnDefs={columnDefs}
Expand Down
1 change: 1 addition & 0 deletions src/stories/components/GridPopoutEditGeneric.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
return (
<Grid
{...props}
selectable={true}
externalSelectedItems={externalSelectedItems}
setExternalSelectedItems={setExternalSelectedItems}
columnDefs={columnDefs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const GridPopoutEditGenericTemplate: ComponentStory<typeof Grid> = (props: GridP
return (
<Grid
{...props}
selectable={true}
externalSelectedItems={externalSelectedItems}
setExternalSelectedItems={setExternalSelectedItems}
columnDefs={columnDefs}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const GridEditMultiSelectTemplate: ComponentStory<typeof Grid> = (props: GridPro
return (
<Grid
{...props}
selectable={true}
externalSelectedItems={externalSelectedItems}
setExternalSelectedItems={setExternalSelectedItems}
columnDefs={columnDefs}
Expand Down
1 change: 1 addition & 0 deletions src/stories/components/GridReadOnly.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const GridReadOnlyTemplate: ComponentStory<typeof Grid> = (props: GridProps) =>
return (
<Grid
{...props}
selectable={false}
externalSelectedItems={externalSelectedItems}
setExternalSelectedItems={setExternalSelectedItems}
columnDefs={columnDefs}
Expand Down

0 comments on commit f0d8bae

Please sign in to comment.