Skip to content

Commit e2f987e

Browse files
committed
feat(data): allow set data callback
1 parent 23dc5c7 commit e2f987e

File tree

4 files changed

+52
-19
lines changed

4 files changed

+52
-19
lines changed

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
save-prefix=~
1+
save-prefix=^
22
ca=

package-lock.json

Lines changed: 29 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
"@types/classnames": "^2.2.3",
4848
"@types/enzyme": "^3.1.3",
4949
"@types/jest": "^20.0.8",
50-
"@types/lodash": "^4.14.76",
51-
"@types/node": "^7.0.12",
52-
"@types/react": "^16.0.20",
50+
"@types/lodash": "~4.14.150",
51+
"@types/node": "~10.17.21",
52+
"@types/react": "~16.9.4",
5353
"@types/react-dom": "^16.0.2",
5454
"autoprefixer": "~6.4.0",
5555
"awesome-typescript-loader": "^3.2.3",
@@ -100,7 +100,7 @@
100100
"tslint-eslint-rules": "^4.1.1",
101101
"tslint-language-service": "^0.9.6",
102102
"tslint-react": "^3.0.0",
103-
"typescript": "^2.4.2",
103+
"typescript": "~3.7.5",
104104
"typings-for-css-modules-loader": "^1.6.1",
105105
"validate-commit-msg": "^2.14.0",
106106
"watch": "^1.0.2",
@@ -131,4 +131,4 @@
131131
"next": "latest"
132132
}
133133
}
134-
}
134+
}

src/lib/components/grid.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Grid,
1111
IBuilderUpdateContext,
1212
IColDescriptor,
13+
IGridDataChange,
1314
IGridDataResult,
1415
IGridDimension,
1516
IGridOpts,
@@ -25,6 +26,7 @@ export interface IGridProps extends IGridOpts {
2526
data?: Array<Array<IGridDataResult<any>>>;
2627
cellRenderer?(context: IBuilderUpdateContext): ReactElement<any> | string | undefined;
2728
headerCellRenderer?(context: IBuilderUpdateContext): ReactElement<any> | string | undefined;
29+
setData?(changes: Array<IGridDataChange<any>>): void;
2830
}
2931

3032
export interface IGridState { }
@@ -46,6 +48,21 @@ export class ReactGrid extends Component<IGridProps, IGridState> {
4648
this.gridContainer.style.width = '100%';
4749
const { rows, cols, data, ...gridOpts } = this.props;
4850
this.grid = create(gridOpts);
51+
const origSet = this.grid.dataModel.set;
52+
this.grid.dataModel.set = (rowOrData: number | Array<IGridDataChange<any>>, c?: number, datum?: string | string[]) => {
53+
const dataChanges = !Array.isArray(rowOrData)
54+
? [{
55+
row: rowOrData,
56+
col: c as number,
57+
value: datum
58+
59+
}]
60+
: rowOrData;
61+
if (this.props.setData) {
62+
this.props.setData(dataChanges);
63+
}
64+
origSet.call(this.grid.dataModel, dataChanges);
65+
};
4966
}
5067

5168
ensureGridContainerInDOM() {

0 commit comments

Comments
 (0)