diff --git a/packages/abc/st/demo/edit-row.md b/packages/abc/st/demo/edit-row.md index ca339d191..d5fd77d45 100644 --- a/packages/abc/st/demo/edit-row.md +++ b/packages/abc/st/demo/edit-row.md @@ -16,7 +16,6 @@ Table with editable rows. ```ts import { Component, ViewChild } from '@angular/core'; import { STColumn, STComponent, STData } from '@delon/abc/st'; -import { deepCopy } from '@delon/util'; import { NzMessageService } from 'ng-zorro-antd/message'; @Component({ @@ -82,10 +81,7 @@ export class DemoComponent { constructor(private msg: NzMessageService) {} private submit(i: STData): void { - // Remove _values - const copyI = deepCopy(i); - delete copyI._values; - this.msg.success(JSON.stringify(copyI)); + this.msg.success(JSON.stringify(this.st.pureItem(i))); this.updateEdit(i, false); } diff --git a/packages/abc/st/index.en-US.md b/packages/abc/st/index.en-US.md index d9b4bba99..32d55db81 100644 --- a/packages/abc/st/index.en-US.md +++ b/packages/abc/st/index.en-US.md @@ -101,6 +101,7 @@ When an exception is thrown when parsing column data, *INVALID DATA* will be for | `reset(extraParams?: any, options?: STLoadOptions)` | Reset data and `pi` to `1`, including single multi-select, sort, filter status (Covered default state) | | `removeRow(data: STData | STData[] | number)` | Remove a row in the table | | `setRow(index: number | STData, item: STData, options?: { refreshSchema?: boolean; emitReload?: boolean })` | Sets the row value for the `index` in the table | +| `pureItem(itemOrIndex: STData | number)` | Return pure data, `st` internally maintains a set of data for caching, this part of data may affect the backend | | `clear(cleanStatus = true)` | Clear all data | | `clearStatus()` | Clean all status (like this: single multi-select, sort, filter status) | | `clearCheck()` | Clear all `checkbox` | diff --git a/packages/abc/st/index.zh-CN.md b/packages/abc/st/index.zh-CN.md index 67ea62564..65968f401 100644 --- a/packages/abc/st/index.zh-CN.md +++ b/packages/abc/st/index.zh-CN.md @@ -101,6 +101,7 @@ module: import { STModule } from '@delon/abc/st'; | `reset(extraParams?: any, options?: STLoadOptions)` | 重置且重新设置 `pi` 为 `1`,包含单多选、排序、过滤状态(同默认状态一并清除) | | `removeRow(data: STData | STData[] | number)` | 移除行 | | `setRow(index: number | STData, item: STData, options?: { refreshSchema?: boolean; emitReload?: boolean })` | 修改行数据,支持部分字段更新 | +| `pureItem(itemOrIndex: STData | number)` | 返回纯净数据,`st` 内部会维护一组用于缓存的数据,这部分数据可能会影响后端 | | `clear(cleanStatus = true)` | 清空所有数据 | | `clearStatus()` | 清空所有状态(包含单多选、排序、过滤状态) | | `clearCheck()` | 清除所有 `checkbox` | diff --git a/packages/abc/st/st.component.ts b/packages/abc/st/st.component.ts index 83c9fe08d..63bd567a6 100644 --- a/packages/abc/st/st.component.ts +++ b/packages/abc/st/st.component.ts @@ -36,6 +36,7 @@ import { AlainConfigService, AlainSTConfig, BooleanInput, + deepCopy, deepMergeKey, InputBoolean, InputNumber, @@ -856,6 +857,23 @@ export class STComponent implements AfterViewInit, OnChanges, OnDestroy { this._data = this.dataSource.optimizeData({ columns: this._columns, result: this._data, rowClassName: this.rowClassName }); } + /** + * Return pure data, `st` internally maintains a set of data for caching, this part of data may affect the backend + * + * 返回纯净数据,`st` 内部会维护一组用于缓存的数据,这部分数据可能会影响后端 + */ + pureItem(itemOrIndex: STData | number): STData | null { + if (typeof itemOrIndex === 'number') { + itemOrIndex = this._data[itemOrIndex]; + } + if (!itemOrIndex) { + return null; + } + const copyItem = deepCopy(itemOrIndex); + delete copyItem._values; + return copyItem; + } + ngAfterViewInit(): void { this.columnSource.restoreAllRender(this._columns); } diff --git a/packages/abc/st/test/st.spec.ts b/packages/abc/st/test/st.spec.ts index 4ac699e77..3be307f48 100644 --- a/packages/abc/st/test/st.spec.ts +++ b/packages/abc/st/test/st.spec.ts @@ -1593,6 +1593,26 @@ describe('abc: table', () => { expect(comp.list.length).toBe(PS); page.asyncEnd(); })); + describe('#pureItem', () => { + it('should be deleted _values', fakeAsync(() => { + page.cd(); + expect(comp.list[0]._values).not.toBeUndefined(); + expect(comp.pureItem(comp.list[0])!._values).toBeUndefined(); + page.asyncEnd(); + })); + it('should be deleted _values via index', fakeAsync(() => { + page.cd(); + expect(comp.list[0]._values).not.toBeUndefined(); + expect(comp.pureItem(0)!._values).toBeUndefined(); + page.asyncEnd(); + })); + it('should be return null when not found row via index', fakeAsync(() => { + page.cd(); + expect(comp.list[0]._values).not.toBeUndefined(); + expect(comp.pureItem(PS + 10)).toBe(null); + page.asyncEnd(); + })); + }); }); describe('#export', () => { let exportSrv: STExport;