Skip to content

Commit

Permalink
feat(module:table): add nzSortDirections to table global config (#6613)…
Browse files Browse the repository at this point in the history
… (#8721)
  • Loading branch information
sharakouze authored Nov 22, 2024
1 parent 860df87 commit eb1fdc5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions components/core/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@ export interface TableConfig {
nzShowSizeChanger?: boolean;
nzSimple?: boolean;
nzHideOnSinglePage?: boolean;
/**
* @see {@link NzTableSortOrder}
*/
nzSortDirections?: Array<string | 'ascend' | 'descend' | null>;
}

export interface TabsConfig {
Expand Down
6 changes: 3 additions & 3 deletions components/table/doc/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ Selection property

Sort property

| Property | Description | Type | Default |
|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|-------------------------------|
| Property | Description | Type | Default | Global Config |
|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|-------------------------------|---------------|
| `[nzShowSort]` | Whether to display sorting | `boolean` | - |
| `[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` | - |
| `[nzSortOrder]` | Sort direction | `'ascend' \| 'descend' \| null` | - |
| `[nzSortDirections]` | Supported sort order, could be `'ascend'`, `'descend'`, `null` | `Array<'ascend' \| 'descend' \| null>` | `['ascend', 'descend', null]` |
| `[nzSortDirections]` | Supported sort order, could be `'ascend'`, `'descend'`, `null` | `Array<'ascend' \| 'descend' \| null>` | `['ascend', 'descend', null]` ||
| `(nzSortOrderChange)` | Callback when sort direction changes | `EventEmitter<'ascend' \| 'descend' \| null>` | - |

Filter property
Expand Down
6 changes: 3 additions & 3 deletions components/table/doc/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ Table 组件同时具备了易用性和高度可定制性

排序属性

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

Expand Down
8 changes: 7 additions & 1 deletion components/table/src/cell/th-addon.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import { Subject, fromEvent } from 'rxjs';
import { filter, takeUntil } from 'rxjs/operators';

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

import { NzTableFilterComponent } from '../addon/filter.component';
Expand All @@ -36,6 +37,8 @@ import {
NzTableSortOrder
} from '../table.types';

const NZ_CONFIG_MODULE_NAME: NzConfigKey = 'table';

@Component({
selector:
'th[nzColumnKey], th[nzSortFn], th[nzSortOrder], th[nzFilters], th[nzShowSort], th[nzShowFilter], th[nzCustomFilter]',
Expand Down Expand Up @@ -82,6 +85,8 @@ import {
standalone: true
})
export class NzThAddOnComponent<T> implements OnChanges, OnInit {
readonly _nzModuleName: NzConfigKey = NZ_CONFIG_MODULE_NAME;

manualClickOrder$ = new Subject<NzThAddOnComponent<T>>();
calcOperatorChange$ = new Subject<void>();
nzFilterValue: NzTableFilterValue = null;
Expand All @@ -94,7 +99,7 @@ export class NzThAddOnComponent<T> implements OnChanges, OnInit {
@Input() nzFilterMultiple = true;
@Input() nzSortOrder: NzTableSortOrder = null;
@Input() nzSortPriority: number | boolean = false;
@Input() nzSortDirections: NzTableSortOrder[] = ['ascend', 'descend', null];
@Input() @WithConfig() nzSortDirections: NzTableSortOrder[] = ['ascend', 'descend', null];
@Input() nzFilters: NzTableFilterList = [];
@Input() nzSortFn: NzTableSortFn<T> | boolean | null = null;
@Input() nzFilterFn: NzTableFilterFn<T> | boolean | null = null;
Expand Down Expand Up @@ -135,6 +140,7 @@ export class NzThAddOnComponent<T> implements OnChanges, OnInit {
}

constructor(
public nzConfigService: NzConfigService,
private host: ElementRef<HTMLElement>,
private cdr: ChangeDetectorRef,
private ngZone: NgZone,
Expand Down

0 comments on commit eb1fdc5

Please sign in to comment.