Skip to content

Commit 409169a

Browse files
authored
fix(abc:st): fix can't addRow in group columns (#1871)
1 parent afb1287 commit 409169a

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

packages/abc/st/demo/grouping-columns.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ title:
1414
Group table head with `columns[n].children`.
1515

1616
```ts
17-
import { Component } from '@angular/core';
17+
import { Component, viewChild } from '@angular/core';
1818

19-
import { STColumn, STModule } from '@delon/abc/st';
19+
import { STColumn, STComponent, STModule } from '@delon/abc/st';
20+
import { NzButtonComponent } from 'ng-zorro-antd/button';
2021

2122
@Component({
2223
selector: 'app-demo',
23-
template: ` <st #st [data]="url" [req]="{ params: params }" [columns]="columns" bordered size="middle" />`,
24-
imports: [STModule]
24+
template: `
25+
<button nz-button nzType="primary" (click)="addRow()">addRow</button>
26+
<st #st [data]="url" [req]="{ params: params }" [columns]="columns" bordered size="middle" />
27+
`,
28+
imports: [STModule, NzButtonComponent]
2529
})
2630
export class DemoComponent {
31+
private readonly st = viewChild<STComponent>('st');
2732
url = `/users?total=2&field=list`;
2833
params = { a: 1, b: 2 };
2934
columns: STColumn[] = [
@@ -44,5 +49,22 @@ export class DemoComponent {
4449
]
4550
}
4651
];
52+
53+
addRow(): void {
54+
this.st()?.addRow(
55+
{
56+
id: 3,
57+
email: 'aaa6@qq.com',
58+
picture: {
59+
thumbnail: 'https://randomuser.me/api/portraits/thumb/men/24.jpg'
60+
},
61+
name: {
62+
first: 'first-11',
63+
last: ' last-1'
64+
}
65+
},
66+
{ index: 0 }
67+
);
68+
}
4769
}
4870
```

packages/abc/st/st-column-source.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,6 @@ export class STColumnSource {
417417
const { noIndex } = this.cog;
418418
let checkboxCount = 0;
419419
let radioCount = 0;
420-
let point = 0;
421420
const columns: _STColumn[] = [];
422421

423422
const processItem = (item: _STColumn): _STColumn => {
@@ -520,8 +519,6 @@ export class STColumnSource {
520519
...(typeof item.resizable === 'boolean' ? ({ disabled: !item.resizable } as STResizable) : item.resizable)
521520
};
522521

523-
item.__point = point++;
524-
525522
return item;
526523
};
527524

packages/abc/st/st.component.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -691,19 +691,19 @@ export class STComponent implements AfterViewInit, OnChanges {
691691
}
692692

693693
private _refColAndData(): this {
694-
this._columns.forEach(c => {
694+
this._columns.forEach((c, cIdx) => {
695695
this._data.forEach((i, idx) => {
696696
const values = i._values as _STDataValue[];
697697
if (c.type === 'no') {
698698
const text = `${this.dataSource.getNoIndex(i, c, idx)}`;
699-
values[c.__point!] = {
699+
values[cIdx] = {
700700
text,
701701
_text: text,
702702
org: idx,
703703
safeType: 'text'
704704
} as _STDataValue;
705705
}
706-
values[c.__point!].props = this.dataSource.getCell(c, i, idx);
706+
values[cIdx].props = this.dataSource.getCell(c, i, idx);
707707
});
708708
});
709709

packages/abc/st/st.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export interface _STColumn extends STColumn {
4949
_width?: number;
5050
_left?: string | boolean;
5151
_right?: string | boolean;
52-
__point?: number;
5352
__renderTitle?: TemplateRef<any>;
5453
__render?: TemplateRef<any>;
5554
}

0 commit comments

Comments
 (0)