Skip to content

Commit c74c992

Browse files
authoredNov 25, 2022
feat(abc:st): columns support null, undefined (#1559)
1 parent 4b00b21 commit c74c992

7 files changed

+28
-14
lines changed
 

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,9 @@ export class STColumnSource {
402402
list: STColumn[],
403403
options: STColumnSourceProcessOptions
404404
): { columns: _STColumn[]; headers: _STHeader[][]; headerWidths: string[] | null } {
405-
if (!list || list.length === 0) throw new Error(`[st]: the columns property muse be define!`);
406-
405+
if (!list || list.length === 0) {
406+
return { columns: [], headers: [], headerWidths: null };
407+
}
407408
const { noIndex } = this.cog;
408409
let checkboxCount = 0;
409410
let radioCount = 0;

‎packages/abc/st/st.component.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
[nzFrontPagination]="false"
3434
[nzBordered]="bordered"
3535
[nzSize]="size"
36-
[nzLoading]="_loading"
36+
[nzLoading]="noColumns || _loading"
3737
[nzLoadingDelay]="loadingDelay"
3838
[nzLoadingIndicator]="loadingIndicator"
3939
[nzTitle]="header!"
@@ -54,6 +54,7 @@
5454
[nzShowTotal]="totalTpl"
5555
[nzWidthConfig]="_widthConfig"
5656
(contextmenu)="onContextmenu($event)"
57+
[class.st__no-column]="noColumns"
5758
>
5859
<thead *ngIf="showHeader">
5960
<tr *ngFor="let row of _headers; let rowFirst = first">

‎packages/abc/st/st.component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export class STComponent implements AfterViewInit, OnChanges, OnDestroy {
162162
this.updateTotalTpl();
163163
}
164164
@Input() data!: string | STData[] | Observable<STData[]>;
165-
@Input() columns: STColumn[] = [];
165+
@Input() columns?: STColumn[] | null;
166166
@Input() contextmenu?: STContextmenuFn | null;
167167
@Input() @InputNumber() ps = 10;
168168
@Input() @InputNumber() pi = 1;
@@ -244,6 +244,10 @@ export class STComponent implements AfterViewInit, OnChanges, OnDestroy {
244244
return this._data;
245245
}
246246

247+
get noColumns(): boolean {
248+
return this.columns == null;
249+
}
250+
247251
constructor(
248252
@Optional() @Inject(ALAIN_I18N_TOKEN) i18nSrv: AlainI18NService,
249253
private cdr: ChangeDetectorRef,

‎packages/abc/st/st.interfaces.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export interface STReq {
8282
*/
8383
allInBody?: boolean;
8484
/**
85-
* 是否延迟加载数据,即渲染结束后不会主动发起请求,默认:`false`
85+
* 是否延迟加载数据,即渲染结束后不会主动发起请求,在适当的时机调用 `resetColumns` 来渲染,默认:`false`
8686
*/
8787
lazyLoad?: boolean;
8888
/**

‎packages/abc/st/style/index.less

+10
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@
154154
}
155155
}
156156

157+
&__no-column {
158+
.@{ant-prefix}-table {
159+
height: @st-no-column-height;
160+
161+
&-content {
162+
display: none;
163+
}
164+
}
165+
}
166+
157167
@media screen and (min-width: @nz-table-rep-min-width) {
158168
&__width {
159169
&-strict {

‎packages/abc/st/test/st-column-source.spec.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,12 @@ describe('st: column-source', () => {
4949
page = new PageObject();
5050
}
5151

52-
it('should be throw error when is empty columns', () => {
53-
expect(() => {
54-
genModule({});
55-
srv.process(null!, { widthMode: null!, resizable: {}, safeType: 'safeHtml' });
56-
}).toThrow();
57-
expect(() => {
58-
genModule({});
59-
srv.process([], options);
60-
}).toThrow();
52+
it('should be support empty columns', () => {
53+
genModule({});
54+
const res = srv.process([], options);
55+
expect(res.columns.length).toBe(0);
56+
expect(res.headers.length).toBe(0);
57+
expect(res.headerWidths).toBe(null);
6158
});
6259

6360
describe('[columns property]', () => {

‎packages/abc/theme-default.less

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@st-resizable-handle-width: 1px;
66
@st-resizable-handle-height: 60%;
77
@st-resizable-handle-color: @border-color-base;
8+
@st-no-column-height: 100px;
89

910
// sv
1011
// --

0 commit comments

Comments
 (0)
Please sign in to comment.