Skip to content

Commit

Permalink
feat(data): allow set data callback
Browse files Browse the repository at this point in the history
  • Loading branch information
scamden committed Apr 30, 2020
1 parent 23dc5c7 commit e2f987e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
save-prefix=~
save-prefix=^
ca=
42 changes: 29 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
"@types/classnames": "^2.2.3",
"@types/enzyme": "^3.1.3",
"@types/jest": "^20.0.8",
"@types/lodash": "^4.14.76",
"@types/node": "^7.0.12",
"@types/react": "^16.0.20",
"@types/lodash": "~4.14.150",
"@types/node": "~10.17.21",
"@types/react": "~16.9.4",
"@types/react-dom": "^16.0.2",
"autoprefixer": "~6.4.0",
"awesome-typescript-loader": "^3.2.3",
Expand Down Expand Up @@ -100,7 +100,7 @@
"tslint-eslint-rules": "^4.1.1",
"tslint-language-service": "^0.9.6",
"tslint-react": "^3.0.0",
"typescript": "^2.4.2",
"typescript": "~3.7.5",
"typings-for-css-modules-loader": "^1.6.1",
"validate-commit-msg": "^2.14.0",
"watch": "^1.0.2",
Expand Down Expand Up @@ -131,4 +131,4 @@
"next": "latest"
}
}
}
}
17 changes: 17 additions & 0 deletions src/lib/components/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Grid,
IBuilderUpdateContext,
IColDescriptor,
IGridDataChange,
IGridDataResult,
IGridDimension,
IGridOpts,
Expand All @@ -25,6 +26,7 @@ export interface IGridProps extends IGridOpts {
data?: Array<Array<IGridDataResult<any>>>;
cellRenderer?(context: IBuilderUpdateContext): ReactElement<any> | string | undefined;
headerCellRenderer?(context: IBuilderUpdateContext): ReactElement<any> | string | undefined;
setData?(changes: Array<IGridDataChange<any>>): void;
}

export interface IGridState { }
Expand All @@ -46,6 +48,21 @@ export class ReactGrid extends Component<IGridProps, IGridState> {
this.gridContainer.style.width = '100%';
const { rows, cols, data, ...gridOpts } = this.props;
this.grid = create(gridOpts);
const origSet = this.grid.dataModel.set;
this.grid.dataModel.set = (rowOrData: number | Array<IGridDataChange<any>>, c?: number, datum?: string | string[]) => {
const dataChanges = !Array.isArray(rowOrData)
? [{
row: rowOrData,
col: c as number,
value: datum

}]
: rowOrData;
if (this.props.setData) {
this.props.setData(dataChanges);
}
origSet.call(this.grid.dataModel, dataChanges);
};
}

ensureGridContainerInDOM() {
Expand Down

0 comments on commit e2f987e

Please sign in to comment.