Skip to content

Commit b1a3412

Browse files
Merge pull request #463 from qiufeihong2018/fix/enable-column-width-resizing
fix:Enable Column Width Resizing for Merged Header Cells #446
2 parents c981381 + bed79fa commit b1a3412

5 files changed

Lines changed: 12 additions & 3 deletions

File tree

src/lib/Behaviors/DefaultBehavior.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
handleDoubleClick,
77
getScrollOfScrollableElement,
88
isSelectionKey,
9+
getCompatibleCellAndTemplate,
910
} from "../../core";
1011
import {
1112
KeyboardEvent,
@@ -49,6 +50,8 @@ export class DefaultBehavior extends Behavior {
4950
location: PointerLocation,
5051
state: State
5152
): Behavior {
53+
const { cell } = getCompatibleCellAndTemplate(state, location);
54+
5255
// changing behavior will disable all keyboard event handlers
5356
const target = event.target as HTMLDivElement;
5457
if (
@@ -57,7 +60,7 @@ export class DefaultBehavior extends Behavior {
5760
(event.pointerType === "touch" &&
5861
(target.className === "rg-touch-resize-handle" ||
5962
target.className === "rg-resize-handle"))) &&
60-
location.row.idx === 0 &&
63+
(location.row.idx === 0 || cell.type === "header") &&
6164
location.column.resizable &&
6265
location.cellX >
6366
location.column.width -

src/lib/Components/CellRenderer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ export const CellRenderer: React.FC<CellRendererProps> = ({
134134
})}
135135
>
136136
{cellTemplate.render(cellToRender, isMobile ? isInEditMode : false, onCellChanged)}
137-
{location.row.idx === 0 && location.column.resizable && <ResizeHandle />}
137+
{(location.row.idx === 0 || cell.type === 'header' && state.props?.enableColumnResizeOnAllHeaders) && location.column.resizable && <ResizeHandle />}
138138
{state.enableGroupIdRender && cell?.groupId !== undefined && !(isInEditMode && isMobile) && (
139139
<span className="rg-groupId">{cell.groupId}</span>
140140
)}

src/lib/Model/PublicModel.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ export type SelectionMode =
3535
export interface ReactGridProps {
3636
/** Array of `Column`s */
3737
readonly columns: Column[];
38-
/** Array of `Row`s */
38+
/** Array of `Row`s */
3939
readonly rows: Row<Cell>[];
40+
/** Enables column resizing on all header cells */
41+
readonly enableColumnResizeOnAllHeaders?: boolean;
4042
/** Object that contains available custom cell templates */
4143
readonly customCellTemplates?: CellTemplates;
4244
/** Focus position (managed constantly by outer app) */

src/test/TestGrid.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ export const TestGrid: React.FC<TestGridProps> = (props) => {
524524
rows={rows}
525525
columns={columns}
526526
initialFocusLocation={config.initialFocusLocation}
527+
enableColumnResizeOnAllHeaders={config.enableColumnResizeOnAllHeaders}
527528
focusLocation={enableFrozenFocus ? config.focusLocation : undefined}
528529
// onCellsChanged={handleChangesTest2} // TODO This handler should be allowed
529530
onCellsChanged={handleChanges}

src/test/testEnvConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const config: TestConfig = {
88
pinToBody: false,
99
additionalContent: false,
1010
flexRow: false,
11+
enableColumnResizeOnAllHeaders: false,
1112

1213
rgViewportHeight: 600,
1314
rgViewportWidth: 1150,
@@ -196,6 +197,8 @@ export interface TestConfig {
196197
additionalContent: boolean;
197198
flexRow: boolean;
198199

200+
enableColumnResizeOnAllHeaders: boolean;
201+
199202
rgViewportHeight: number;
200203
rgViewportWidth: number;
201204
margin: string;

0 commit comments

Comments
 (0)