Skip to content

Commit e8e950d

Browse files
Grouping (#2106)
* Initial commit * Group by multiple columns * Cleanup viewport rows * memoize group row, add groupRowRenderer prop * Cleanup useViewportColumns * Fix keys * Add column.groupFormatter prop and checkbox column * Checkbox selection for group row * Validate groupBy columns * Ckeck isSelectable * ColSpan * Disable copy/paste and cell drag down on treegrid * Add treegrid aria attributes * Fix rowsCount * Fix rowsCount * Fix aria-rowindex and aria-rowcount and update grouprow props * Change expandedGroupIds/onExpandedGroupIdsChange to props * Use 1 loop * Cleanup * Add GroupCell component * Add row selection for group rows * Cleanup * Handle Home and End keys for GroupRow * Clanup navigation logic * Cleanup * Improve navigation logic * Cleanup * Handle copy/paste * Grouping story * Add select to choose group by field * Use SortableSelect * Cleanup * Improve types * Fic type * Address comments * useFocusRef * Update src/DataGrid.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update src/DataGrid.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update src/types.ts Co-authored-by: Nicolas Stepien <[email protected]> * Update src/types.ts Co-authored-by: Nicolas Stepien <[email protected]> * Fix types * Add stopPropagation helper * Move onExpandedGroupIdsChange check outside * Cleanup * Add groupFocusable and remove __isGroup field * fix dependencies * Fix expandedGroupId * Fix row navigation * fix border styles * Use a single array * Cleanup groupBy columns logic * Link TS issue * Add icon prop to ToggleGroupedFormatter * Cell drag is not supported on a treegrid * Add caret icon * Center align * -moz-middle-with-baseline; * Update changelog * Update src/utils/columnUtils.ts Co-authored-by: Nicolas Stepien <[email protected]> * Address comments * Use the suggested sorting logic * Do not mutate formatterOptions * Make group cell clickable * Mock less files for tests * Inline getVerticalRangeToRender * Update src/DataGrid.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update src/DataGrid.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update src/formatters/ToggleGroupFormatter.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update src/formatters/ToggleGroupFormatter.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Revert jest changes * Cleanup parameters * add grouprow.less * Add a comment * Update src/GroupCell.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update stories/demos/Grouping.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update stories/demos/Grouping.tsx Co-authored-by: Nicolas Stepien <[email protected]> * Update style/index.less Co-authored-by: Nicolas Stepien <[email protected]> * Do not extract all the props * Do not extract focus and keydown Co-authored-by: Nicolas Stepien <[email protected]> Co-authored-by: Nicolas Stepien <[email protected]>
1 parent ebfaa14 commit e8e950d

32 files changed

+889
-386
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
- `rowClass`
1919
- `defaultColumnOptions`
2020
- ⚠️ This replaces the `minColumnWidth` and `defaultFormatter` props
21+
- `groupBy`
22+
- `rowGrouper`
23+
- More info in [#2106](https://github.com/adazzle/react-data-grid/pull/2106)
2124
- `column.cellClass(row)` function support:
2225
- `column = { ..., cellClass(row) { return string; } }`
2326
- `column.minWidth`
@@ -26,6 +29,8 @@
2629
- `column.editor2`
2730
- `column.editorOptions`
2831
- More info in [#2102](https://github.com/adazzle/react-data-grid/pull/2102)
32+
- `column.groupFormatter`
33+
- More info in [#2106](https://github.com/adazzle/react-data-grid/pull/2106)
2934
- `scrollToRow` method
3035
- ⚠️ This replaces the `scrollToRowIndex` prop
3136
- **Removed:**

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"react-dom": "next",
8484
"react-popper": "^2.2.3",
8585
"react-select": "^3.1.0",
86+
"react-sortable-hoc": "^1.11.0",
8687
"ts-jest": "^26.1.4",
8788
"ts-loader": "^8.0.2",
8889
"typescript": "~4.0.2"

src/Cell.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,20 @@ function Cell<R, SR>({
7979
onContextMenu={wrapEvent(handleContextMenu, onContextMenu)}
8080
{...props}
8181
>
82-
<column.formatter
83-
column={column}
84-
rowIdx={rowIdx}
85-
row={row}
86-
isCellSelected={isCellSelected}
87-
isRowSelected={isRowSelected}
88-
onRowSelectionChange={onRowSelectionChange}
89-
/>
90-
{dragHandleProps && (
91-
<div className="rdg-cell-drag-handle" {...dragHandleProps} />
82+
{!column.rowGroup && (
83+
<>
84+
<column.formatter
85+
column={column}
86+
rowIdx={rowIdx}
87+
row={row}
88+
isCellSelected={isCellSelected}
89+
isRowSelected={isRowSelected}
90+
onRowSelectionChange={onRowSelectionChange}
91+
/>
92+
{dragHandleProps && (
93+
<div className="rdg-cell-drag-handle" {...dragHandleProps} />
94+
)}
95+
</>
9296
)}
9397
</div>
9498
);

src/Columns.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { SelectCellFormatter } from './formatters';
33
import { Column } from './types';
44
import { stopPropagation } from './utils';
55

6+
export const SELECT_COLUMN_KEY = 'select-row';
7+
68
// TODO: fix type
79
// eslint-disable-next-line @typescript-eslint/no-explicit-any
810
export const SelectColumn: Column<any, any> = {
9-
key: 'select-row',
11+
key: SELECT_COLUMN_KEY,
1012
name: '',
1113
width: 35,
1214
maxWidth: 35,
@@ -33,5 +35,18 @@ export const SelectColumn: Column<any, any> = {
3335
onChange={props.onRowSelectionChange}
3436
/>
3537
);
38+
},
39+
groupFormatter(props) {
40+
return (
41+
<SelectCellFormatter
42+
aria-label="Select Group"
43+
tabIndex={-1}
44+
isCellSelected={props.isCellSelected}
45+
value={props.isRowSelected}
46+
onChange={props.onRowSelectionChange}
47+
// Stop propagation to prevent row selection
48+
onClick={stopPropagation}
49+
/>
50+
);
3651
}
3752
};

0 commit comments

Comments
 (0)