Skip to content

Commit 704badc

Browse files
authored
feat(abc:st): type cell support click (#1873)
1 parent f752c24 commit 704badc

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

packages/abc/st/demo/cell.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,16 @@ export class DemoComponent {
6666
} as CellOptions;
6767
}
6868
},
69-
{ title: '可用', index: 'disabled', width: 64, cell: { type: 'boolean' } },
69+
{
70+
title: '可用',
71+
index: 'disabled',
72+
width: 64,
73+
cell: { type: 'boolean', tooltip: '点击可切换状态' },
74+
className: 'point',
75+
click: i => {
76+
this.st.setRow(i, { disabled: !i.disabled });
77+
}
78+
},
7079
{ title: '注册时间', index: 'registered', width: 180, cell: { type: 'date' } }
7180
];
7281

packages/abc/st/st-td.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<nz-badge [nzStatus]="col.color" [nzText]="col.text" [nz-tooltip]="col.tooltip" />
6666
}
6767
@case ('cell') {
68-
<cell [value]="col.text" [options]="col.cell ?? c.cell" />
68+
<cell [value]="col.text" [options]="col.cell ?? c.cell" (click)="_client()" />
6969
}
7070
@case ('widget') {
7171
<ng-template st-widget-host [record]="i" [column]="c" />

packages/abc/st/st.component.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export class STTdComponent {
153153
return false;
154154
}
155155

156+
_client(): void {
157+
this.c.click?.(this.i, this.stComp);
158+
}
159+
156160
_stopPropagation(ev: Event): void {
157161
ev.preventDefault();
158162
ev.stopPropagation();

packages/abc/st/st.interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ export interface STColumn<T extends STData = any> {
268268
* - `currency` 货币且居右(若 `className` 存在则优先)
269269
* - `date` 日期格式且居中(若 `className` 存在则优先),使用 `dateFormat` 自定义格式
270270
* - `yn` 将`boolean`类型徽章化 [document](https://ng-alain.com/docs/data-render#yn)
271-
* - `cell` 使用 `cell` 组件渲染 [document](https://ng-alain.com/components/cell)
271+
* - `cell` 可指定 `click`,使用 `cell` 组件渲染 [document](https://ng-alain.com/components/cell)
272272
* - `widget` 使用自定义小部件动态创建
273273
*/
274274
type?:

packages/abc/st/test/st.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ describe('abc: st', () => {
394394
.expectElCount('.cell', PS)
395395
.expectElCount('.ant-checkbox', 1);
396396
}));
397+
it('can be click', fakeAsync(() => {
398+
const columns: STColumn[] = [{ index: 'id', cell: { type: 'boolean' }, click: jasmine.createSpy() }];
399+
page.updateColumn(columns).clickCell('.cell');
400+
expect(columns[0].click).toHaveBeenCalled();
401+
}));
397402
});
398403
describe('[other]', () => {
399404
it('should custom render via format', fakeAsync(() => {

0 commit comments

Comments
 (0)