Skip to content

Commit

Permalink
fix(abc:st): fix can't addRow in group columns (#1871)
Browse files Browse the repository at this point in the history
  • Loading branch information
cipchk authored Jan 19, 2025
1 parent afb1287 commit 409169a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
30 changes: 26 additions & 4 deletions packages/abc/st/demo/grouping-columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ title:
Group table head with `columns[n].children`.

```ts
import { Component } from '@angular/core';
import { Component, viewChild } from '@angular/core';

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

@Component({
selector: 'app-demo',
template: ` <st #st [data]="url" [req]="{ params: params }" [columns]="columns" bordered size="middle" />`,
imports: [STModule]
template: `
<button nz-button nzType="primary" (click)="addRow()">addRow</button>
<st #st [data]="url" [req]="{ params: params }" [columns]="columns" bordered size="middle" />
`,
imports: [STModule, NzButtonComponent]
})
export class DemoComponent {
private readonly st = viewChild<STComponent>('st');
url = `/users?total=2&field=list`;
params = { a: 1, b: 2 };
columns: STColumn[] = [
Expand All @@ -44,5 +49,22 @@ export class DemoComponent {
]
}
];

addRow(): void {
this.st()?.addRow(
{
id: 3,
email: '[email protected]',
picture: {
thumbnail: 'https://randomuser.me/api/portraits/thumb/men/24.jpg'
},
name: {
first: 'first-11',
last: ' last-1'
}
},
{ index: 0 }
);
}
}
```
3 changes: 0 additions & 3 deletions packages/abc/st/st-column-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ export class STColumnSource {
const { noIndex } = this.cog;
let checkboxCount = 0;
let radioCount = 0;
let point = 0;
const columns: _STColumn[] = [];

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

item.__point = point++;

return item;
};

Expand Down
6 changes: 3 additions & 3 deletions packages/abc/st/st.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,19 +691,19 @@ export class STComponent implements AfterViewInit, OnChanges {
}

private _refColAndData(): this {
this._columns.forEach(c => {
this._columns.forEach((c, cIdx) => {
this._data.forEach((i, idx) => {
const values = i._values as _STDataValue[];
if (c.type === 'no') {
const text = `${this.dataSource.getNoIndex(i, c, idx)}`;
values[c.__point!] = {
values[cIdx] = {
text,
_text: text,
org: idx,
safeType: 'text'
} as _STDataValue;
}
values[c.__point!].props = this.dataSource.getCell(c, i, idx);
values[cIdx].props = this.dataSource.getCell(c, i, idx);
});
});

Expand Down
1 change: 0 additions & 1 deletion packages/abc/st/st.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface _STColumn extends STColumn {
_width?: number;
_left?: string | boolean;
_right?: string | boolean;
__point?: number;
__renderTitle?: TemplateRef<any>;
__render?: TemplateRef<any>;
}
Expand Down

0 comments on commit 409169a

Please sign in to comment.