From ac94b4fe5607c547147c6dd14aa98f626b7c6514 Mon Sep 17 00:00:00 2001 From: mikproto Date: Thu, 1 Oct 2020 13:12:38 +0300 Subject: [PATCH] quick fix --- package.json | 2 +- src/components/data/columnService.ts | 41 ++++++++++++++++++++++------ src/components/data/revogr-data.tsx | 10 +++++-- src/index.html | 4 +-- src/utilsExternal/generate-data.js | 12 ++++++-- 5 files changed, 52 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 862ac81d..5566bd80 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@revolist/revogrid", - "version": "1.5.17", + "version": "1.5.18", "description": "Virtual reactive data grid component - RevoGrid.", "license": "MIT", "bugs": { diff --git a/src/components/data/columnService.ts b/src/components/data/columnService.ts index 75d70a34..a81e97f0 100644 --- a/src/components/data/columnService.ts +++ b/src/components/data/columnService.ts @@ -40,7 +40,12 @@ export default class ColumnService implements ColumnServiceI { isReadOnly(r: number, c: number): boolean { const readOnly: RevoGrid.ReadOnlyFormat = this.columns[c]?.readonly; if (typeof readOnly === 'function') { - return readOnly(this.rowDataModel(r, c)); + const data = this.rowDataModel(r, c); + // quick fix, remove + if (!data) { + return true; + } + return readOnly(data); } return readOnly; } @@ -56,7 +61,12 @@ export default class ColumnService implements ColumnServiceI { }; const extraPropsFunc = this.columns[c]?.cellProperties; if (extraPropsFunc) { - const extra = extraPropsFunc(this.rowDataModel(r, c)); + const data = this.rowDataModel(r, c); + // quick fix, remove + if (!data) { + return props; + } + const extra = extraPropsFunc(data); if (!extra) { return props; } @@ -80,7 +90,12 @@ export default class ColumnService implements ColumnServiceI { customRenderer(r: number, c: number): VNode | string | void { const tpl = this.columns[c]?.cellTemplate; if (tpl) { - return tpl(h as unknown as RevoGrid.HyperFunc, this.rowDataModel(r, c)); + const data = this.rowDataModel(r, c); + // quick fix, remove + if (!data) { + return; + } + return tpl(h as unknown as RevoGrid.HyperFunc, data); } return; } @@ -92,27 +107,37 @@ export default class ColumnService implements ColumnServiceI { } getCellData(r: number, c: number): string { - const {prop, model} = this.rowDataModel(r, c); - return ColumnService.getData(model[prop as number]); + const data = this.rowDataModel(r, c); + // quick fix, remove + if (!data) { + return ''; + } + return ColumnService.getData(data.model[data.prop as number]); } getSaveData(rowIndex: number, c: number, val?: string): BeforeSaveDataDetails { - const {prop, model } = this.rowDataModel(rowIndex, c); if (typeof val === 'undefined') { val = this.getCellData(rowIndex, c) } - return { prop, rowIndex, val, model, type: this.dataStore.get('type')}; + const data = this.rowDataModel(rowIndex, c); + if (!data) { + throw new Error('Data expcted'); + } + return { prop: data.prop, rowIndex, val, model: data.model, type: this.dataStore.get('type')}; } getCellEditor(_r: number, c: number): string | undefined { return this.columns[c]?.editor; } - rowDataModel(r: number, c: number): ColumnDataSchemaModel { + rowDataModel(r: number, c: number): ColumnDataSchemaModel|void { const column = this.columns[c]; const prop: ColumnProp | undefined = column?.prop; const data: DataSource = this.dataStore.get('items'); + if (!data[r]) { + return; + } const model: DataType = data[r] || {}; return {prop, model, data, column}; } diff --git a/src/components/data/revogr-data.tsx b/src/components/data/revogr-data.tsx index 23f0a580..fc51e51e 100644 --- a/src/components/data/revogr-data.tsx +++ b/src/components/data/revogr-data.tsx @@ -49,7 +49,7 @@ export class RevogrData { } const rowsEls: VNode[] = []; for (let row of this.rows) { - const cells: VNode[] = []; + const cells: (VNode|string|void)[] = []; const rowClass = this.rowClass ? this.columnService.getRowClass(row.itemIndex, this.rowClass) : ''; for (let col of this.cols) { cells.push(this.getCellRenderer(row, col)); @@ -59,7 +59,7 @@ export class RevogrData { return rowsEls; } - private getCellRenderer(row: RevoGrid.VirtualPositionItem, col: RevoGrid.VirtualPositionItem): VNode { + private getCellRenderer(row: RevoGrid.VirtualPositionItem, col: RevoGrid.VirtualPositionItem): VNode|string|void { const defaultProps: RevoGrid.CellProps = { [DATA_COL]: col.itemIndex, [DATA_ROW]: row.itemIndex, @@ -73,9 +73,13 @@ export class RevogrData { if (custom) { return
{custom}
; } + const model = this.columnService.rowDataModel(row.itemIndex, col.itemIndex); + if (!model) { + return; + } return
this.dragStartCell.emit(e)}/>
; diff --git a/src/index.html b/src/index.html index 4dab7abf..fefffe34 100644 --- a/src/index.html +++ b/src/index.html @@ -53,14 +53,14 @@
- +