Skip to content

Commit eb1fdc5

Browse files
authored
feat(module:table): add nzSortDirections to table global config (#6613) (#8721)
1 parent 860df87 commit eb1fdc5

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

components/core/config/config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ export interface TableConfig {
295295
nzShowSizeChanger?: boolean;
296296
nzSimple?: boolean;
297297
nzHideOnSinglePage?: boolean;
298+
/**
299+
* @see {@link NzTableSortOrder}
300+
*/
301+
nzSortDirections?: Array<string | 'ascend' | 'descend' | null>;
298302
}
299303

300304
export interface TabsConfig {

components/table/doc/index.en-US.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ Selection property
125125

126126
Sort property
127127

128-
| Property | Description | Type | Default |
129-
|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|-------------------------------|
128+
| Property | Description | Type | Default | Global Config |
129+
|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|-------------------------------|---------------|
130130
| `[nzShowSort]` | Whether to display sorting | `boolean` | - |
131131
| `[nzSortFn]` | Sort function used to sort the data on client side (ref to Array.sort compareFunction). Should be set to `true` when using server side sorting | `NzTableSortFn<T> \| boolean` | - |
132132
| `[nzSortOrder]` | Sort direction | `'ascend' \| 'descend' \| null` | - |
133-
| `[nzSortDirections]` | Supported sort order, could be `'ascend'`, `'descend'`, `null` | `Array<'ascend' \| 'descend' \| null>` | `['ascend', 'descend', null]` |
133+
| `[nzSortDirections]` | Supported sort order, could be `'ascend'`, `'descend'`, `null` | `Array<'ascend' \| 'descend' \| null>` | `['ascend', 'descend', null]` ||
134134
| `(nzSortOrderChange)` | Callback when sort direction changes | `EventEmitter<'ascend' \| 'descend' \| null>` | - |
135135

136136
Filter property

components/table/doc/index.zh-CN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ Table 组件同时具备了易用性和高度可定制性
125125

126126
排序属性
127127

128-
| 参数 | 说明 | 类型 | 默认值 |
129-
|-----------------------|----------------------------------------------------------------|-----------------------------------------------|-------------------------------|
128+
| 参数 | 说明 | 类型 | 默认值 | 全局配置 |
129+
|-----------------------|----------------------------------------------------------------|-----------------------------------------------|-------------------------------|------|
130130
| `[nzShowSort]` | 是否显示排序 | `boolean` | - |
131131
| `[nzSortFn]` | 排序函数,前端排序使用一个函数(参考 Array.sort 的 compareFunction),服务端排序时传入 true | `NzTableSortFn<T> \| boolean` | - |
132-
| `[nzSortDirections]` | 支持的排序方式,取值为 `'ascend'`, `'descend'`, `null` | `Array<'ascend' \| 'descend' \| null>` | `['ascend', 'descend', null]` |
132+
| `[nzSortDirections]` | 支持的排序方式,取值为 `'ascend'`, `'descend'`, `null` | `Array<'ascend' \| 'descend' \| null>` | `['ascend', 'descend', null]` ||
133133
| `[nzSortOrder]` | 当前排序状态,可双向绑定 | 'descend' \| 'ascend' \| null | null |
134134
| `(nzSortOrderChange)` | 排序状态改变回调 | `EventEmitter<'descend' \| 'ascend' \| null>` | - |
135135

components/table/src/cell/th-addon.component.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
import { Subject, fromEvent } from 'rxjs';
2525
import { filter, takeUntil } from 'rxjs/operators';
2626

27+
import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
2728
import { NzDestroyService } from 'ng-zorro-antd/core/services';
2829

2930
import { NzTableFilterComponent } from '../addon/filter.component';
@@ -36,6 +37,8 @@ import {
3637
NzTableSortOrder
3738
} from '../table.types';
3839

40+
const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'table';
41+
3942
@Component({
4043
selector:
4144
'th[nzColumnKey], th[nzSortFn], th[nzSortOrder], th[nzFilters], th[nzShowSort], th[nzShowFilter], th[nzCustomFilter]',
@@ -82,6 +85,8 @@ import {
8285
standalone: true
8386
})
8487
export class NzThAddOnComponent<T> implements OnChanges, OnInit {
88+
readonly _nzModuleName: NzConfigKey = NZ_CONFIG_MODULE_NAME;
89+
8590
manualClickOrder$ = new Subject<NzThAddOnComponent<T>>();
8691
calcOperatorChange$ = new Subject<void>();
8792
nzFilterValue: NzTableFilterValue = null;
@@ -94,7 +99,7 @@ export class NzThAddOnComponent<T> implements OnChanges, OnInit {
9499
@Input() nzFilterMultiple = true;
95100
@Input() nzSortOrder: NzTableSortOrder = null;
96101
@Input() nzSortPriority: number | boolean = false;
97-
@Input() nzSortDirections: NzTableSortOrder[] = ['ascend', 'descend', null];
102+
@Input() @WithConfig() nzSortDirections: NzTableSortOrder[] = ['ascend', 'descend', null];
98103
@Input() nzFilters: NzTableFilterList = [];
99104
@Input() nzSortFn: NzTableSortFn<T> | boolean | null = null;
100105
@Input() nzFilterFn: NzTableFilterFn<T> | boolean | null = null;
@@ -135,6 +140,7 @@ export class NzThAddOnComponent<T> implements OnChanges, OnInit {
135140
}
136141

137142
constructor(
143+
public nzConfigService: NzConfigService,
138144
private host: ElementRef<HTMLElement>,
139145
private cdr: ChangeDetectorRef,
140146
private ngZone: NgZone,

0 commit comments

Comments
 (0)