Skip to content

Commit 20c478c

Browse files
diegomurakamiconor-j-malone
authored andcommitted
Fix Issue 556 (adazzle#561)
* Fix the bug * Allow only -1,-1 changes to grid selection * Add test * Add check for the parameter -1 * Remove fdescribe
1 parent 975fa02 commit 20c478c

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/Grid.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const Grid = React.createClass({
9696
onSort={this.props.onSort}
9797
onScroll={this.onHeaderScroll}
9898
getValidFilterValues={this.props.getValidFilterValues}
99+
cellMetaData={this.props.cellMetaData}
99100
/>
100101
{this.props.rowsCount >= 1 || (this.props.rowsCount === 0 && !this.props.emptyRowsView) ?
101102
<div ref="viewPortContainer" tabIndex="0" onKeyDown={this.props.onViewportKeydown} onKeyUp={this.props.onViewportKeyup} onDoubleClick={this.props.onViewportDoubleClick} onDragStart={this.props.onViewportDragStart} onDragEnd={this.props.onViewportDragEnd}>

src/Header.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const HeaderRow = require('./HeaderRow');
88
const getScrollbarSize = require('./getScrollbarSize');
99
const PropTypes = React.PropTypes;
1010
const createObjectWithProperties = require('./createObjectWithProperties');
11+
const cellMetaDataShape = require('./PropTypeShapes/CellMetaDataShape');
1112

1213
type Column = {
1314
width: number
@@ -28,7 +29,8 @@ const Header = React.createClass({
2829
onColumnResize: PropTypes.func,
2930
onScroll: PropTypes.func,
3031
draggableHeaderCell: PropTypes.func,
31-
getValidFilterValues: PropTypes.func
32+
getValidFilterValues: PropTypes.func,
33+
cellMetaData: PropTypes.shape(cellMetaDataShape)
3234
},
3335

3436
getInitialState(): {resizing: any} {
@@ -182,6 +184,11 @@ const Header = React.createClass({
182184
return createObjectWithProperties(this.props, knownDivPropertyKeys);
183185
},
184186

187+
// Set the cell selection to -1 x -1 when clicking on the header
188+
onHeaderClick() {
189+
this.props.cellMetaData.onCellClick({rowIdx: -1, idx: -1 });
190+
},
191+
185192
render(): ?ReactElement {
186193
let className = joinClasses({
187194
'react-grid-Header': true,
@@ -190,7 +197,7 @@ const Header = React.createClass({
190197
let headerRows = this.getHeaderRows();
191198

192199
return (
193-
<div {...this.getKnownDivProps()} style={this.getStyle()} className={className}>
200+
<div {...this.getKnownDivProps()} style={this.getStyle()} className={className} onClick={this.onHeaderClick}>
194201
{headerRows}
195202
</div>
196203
);

src/ReactDataGrid.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ const ReactDataGrid = React.createClass({
189189
this.props.onCellSelected(selected);
190190
}
191191
});
192+
} else if (selected.rowIdx === -1 && selected.idx === -1) {
193+
// When it's outside of the grid, set rowIdx anyway
194+
this.setState({selected: { idx, rowIdx }});
192195
}
193196
}
194197
},

src/__tests__/Header.spec.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,16 @@ describe('Header Unit Tests', () => {
132132
onColumnResize: jasmine.createSpy(),
133133
onScroll: jasmine.createSpy(),
134134
draggableHeaderCell: jasmine.createSpy(),
135-
getValidFilterValues: jasmine.createSpy()
135+
getValidFilterValues: jasmine.createSpy(),
136+
cellMetaData: {
137+
onCommitCancel: () => {},
138+
onCommit: () => {},
139+
onCellDoubleClick: () => {},
140+
onCellClick: () => { },
141+
handleDragEnterRow: () => {},
142+
handleTerminateDrag: () => {},
143+
selected: { rowIdx: 0, id: 1 }
144+
}
136145
};
137146
it('passes classname property', () => {
138147
const wrapper = renderComponent(testAllProps);
@@ -178,5 +187,14 @@ describe('Header Unit Tests', () => {
178187
expect(headerDiv.props().draggableHeaderCell).toBeUndefined();
179188
expect(headerDiv.props().getValidFilterValues).toBeUndefined();
180189
});
190+
191+
it('execute onCellClick event on cellMetaData and rowIdx & idx = -1', () => {
192+
spyOn(testAllProps.cellMetaData, 'onCellClick');
193+
const wrapper = renderComponent(testAllProps);
194+
const headerDiv = wrapper.find('div');
195+
headerDiv.simulate('click');
196+
expect(testAllProps.cellMetaData.onCellClick).toHaveBeenCalled();
197+
expect(testAllProps.cellMetaData.onCellClick.calls.mostRecent().args[0]).toEqual({ rowIdx: -1, idx: -1 });
198+
});
181199
});
182200
});

0 commit comments

Comments
 (0)