Skip to content

Commit

Permalink
feat(abc:st): add pureList method (#1126)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Jan 5, 2021
1 parent 92f3390 commit 70270f8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
6 changes: 1 addition & 5 deletions packages/abc/st/demo/edit-row.md
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions packages/abc/st/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
1 change: 1 addition & 0 deletions packages/abc/st/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down
18 changes: 18 additions & 0 deletions packages/abc/st/st.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {
AlainConfigService,
AlainSTConfig,
BooleanInput,
deepCopy,
deepMergeKey,
InputBoolean,
InputNumber,
Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 20 additions & 0 deletions packages/abc/st/test/st.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 70270f8

Please sign in to comment.