Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(abc:st): add arrayProcessMethod in setRow #1853

Merged
merged 2 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/abc/st/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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) |
| `addRow(data: STData | STData[], options?: { index?: number })` | Add a rows in the table |
| `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 |
| `setRow(index: number | STData, item: STData, options?: { refreshSchema?: boolean; emitReload?: boolean; arrayProcessMethod?: 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) |
Expand Down
2 changes: 1 addition & 1 deletion packages/abc/st/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module: import { STModule } from '@delon/abc/st';
| `reset(extraParams?: any, options?: STLoadOptions)` | 重置且重新设置 `pi` 为 `1`,包含单多选、排序、过滤状态(同默认状态一并清除) |
| `addRow(data: STData | STData[], options?: { index?: number })` | 添加行 |
| `removeRow(data: STData | STData[] | number)` | 移除行 |
| `setRow(index: number | STData, item: STData, options?: { refreshSchema?: boolean; emitReload?: boolean })` | 修改行数据,支持部分字段更新 |
| `setRow(index: number | STData, item: STData, options?: { refreshSchema?: boolean; emitReload?: boolean; arrayProcessMethod?: boolean })` | 修改行数据,支持部分字段更新 |
| `pureItem(itemOrIndex: STData | number)` | 返回纯净数据,`st` 内部会维护一组用于缓存的数据,这部分数据可能会影响后端 |
| `clear(cleanStatus = true)` | 清空所有数据 |
| `clearStatus()` | 清空所有状态(包含单多选、排序、过滤状态) |
Expand Down
18 changes: 16 additions & 2 deletions packages/abc/st/st.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,26 @@ export class STComponent implements AfterViewInit, OnChanges {
* this.st.setRow(item, { price: 100 })
* ```
*/
setRow(index: number | STData, item: STData, options?: { refreshSchema?: boolean; emitReload?: boolean }): this {
setRow(
index: number | STData,
item: STData,
options?: {
refreshSchema?: boolean;
emitReload?: boolean;
/**
*
* @param arrayProcessMethod 数组处理方式
* - `true` 表示替换新值,不管新值为哪种类型
* - `false` 表示会合并整个数组(将旧数据与新数据合并成新数组)
*/
arrayProcessMethod?: boolean;
}
): this {
options = { refreshSchema: false, emitReload: false, ...options };
if (typeof index !== 'number') {
index = this._data.indexOf(index);
}
this._data[index] = deepMergeKey(this._data[index], false, item);
this._data[index] = deepMergeKey(this._data[index], options?.arrayProcessMethod ?? false, item);
this.optimizeData();
if (options.refreshSchema) {
this.resetColumns({ emitReload: options.emitReload });
Expand Down
Loading