Add sortColumn to title render (#19012)

Update docs

Update TS interface

Add null

Fix lint error
This commit is contained in:
swillis12 2019-09-25 23:02:08 -07:00 committed by 偏右
parent 90a77c0f02
commit 2c864b9bc6
4 changed files with 9 additions and 4 deletions

View File

@ -1203,12 +1203,13 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
} }
renderColumnTitle(title: ColumnProps<T>['title']) { renderColumnTitle(title: ColumnProps<T>['title']) {
const { filters, sortOrder } = this.state; const { filters, sortOrder, sortColumn } = this.state;
// https://github.com/ant-design/ant-design/issues/11246#issuecomment-405009167 // https://github.com/ant-design/ant-design/issues/11246#issuecomment-405009167
if (title instanceof Function) { if (title instanceof Function) {
return title({ return title({
filters, filters,
sortOrder, sortOrder,
sortColumn,
}); });
} }
return title; return title;

View File

@ -138,7 +138,7 @@ One of the Table `columns` prop for describing the table's columns, Column has t
| sorter | Sort function for local sort, see [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)'s compareFunction. If you need sort buttons only, set to `true` | Function\|boolean | - | | | sorter | Sort function for local sort, see [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)'s compareFunction. If you need sort buttons only, set to `true` | Function\|boolean | - | |
| sortOrder | Order of sorted values: `'ascend'` `'descend'` `false` | boolean\|string | - | | | sortOrder | Order of sorted values: `'ascend'` `'descend'` `false` | boolean\|string | - | |
| sortDirections | supported sort way, could be `'ascend'`, `'descend'` | Array | `['ascend', 'descend']` | 3.15.2 | | sortDirections | supported sort way, could be `'ascend'`, `'descend'` | Array | `['ascend', 'descend']` | 3.15.2 |
| title | Title of this column | ReactNode\|({ sortOrder, filters }) => ReactNode | - | | | title | Title of this column | ReactNode\|({ sortOrder, sortColumn, filters }) => ReactNode | - | |
| width | Width of this column ([width not working?](https://github.com/ant-design/ant-design/issues/13825#issuecomment-449889241)) | string\|number | - | | | width | Width of this column ([width not working?](https://github.com/ant-design/ant-design/issues/13825#issuecomment-449889241)) | string\|number | - | |
| onCell | Set props on per cell | Function(record, rowIndex) | - | | | onCell | Set props on per cell | Function(record, rowIndex) | - | |
| onFilter | Callback executed when the confirm filter button is clicked | Function | - | | | onFilter | Callback executed when the confirm filter button is clicked | Function | - | |

View File

@ -143,7 +143,7 @@ const columns = [
| sorter | 排序函数,本地排序使用一个函数(参考 [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) 的 compareFunction),需要服务端排序可设为 true | Function\|boolean | - | | | sorter | 排序函数,本地排序使用一个函数(参考 [Array.sort](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) 的 compareFunction),需要服务端排序可设为 true | Function\|boolean | - | |
| sortOrder | 排序的受控属性,外界可用此控制列的排序,可设置为 `'ascend'` `'descend'` `false` | boolean\|string | - | | | sortOrder | 排序的受控属性,外界可用此控制列的排序,可设置为 `'ascend'` `'descend'` `false` | boolean\|string | - | |
| sortDirections | 支持的排序方式,取值为 `'ascend'` `'descend'` | Array | `['ascend', 'descend']` | 3.15.2 | | sortDirections | 支持的排序方式,取值为 `'ascend'` `'descend'` | Array | `['ascend', 'descend']` | 3.15.2 |
| title | 列头显示文字(函数用法 `3.10.0` 后支持) | ReactNode\|({ sortOrder, filters }) => ReactNode | - | | | title | 列头显示文字(函数用法 `3.10.0` 后支持) | ReactNode\|({ sortOrder, sortColumn, filters }) => ReactNode | - | |
| width | 列宽度([指定了也不生效?](https://github.com/ant-design/ant-design/issues/13825#issuecomment-449889241) | string\|number | - | | | width | 列宽度([指定了也不生效?](https://github.com/ant-design/ant-design/issues/13825#issuecomment-449889241) | string\|number | - | |
| onCell | 设置单元格属性 | Function(record, rowIndex) | - | | | onCell | 设置单元格属性 | Function(record, rowIndex) | - | |
| onFilter | 本地模式下,确定筛选的运行函数 | Function | - | | | onFilter | 本地模式下,确定筛选的运行函数 | Function | - | |

View File

@ -29,7 +29,11 @@ export interface FilterDropdownProps {
export interface ColumnProps<T> { export interface ColumnProps<T> {
title?: title?:
| React.ReactNode | React.ReactNode
| ((options: { filters: TableStateFilters; sortOrder?: SortOrder }) => React.ReactNode); | ((options: {
filters: TableStateFilters;
sortOrder?: SortOrder;
sortColumn?: ColumnProps<T> | null;
}) => React.ReactNode);
key?: React.Key; key?: React.Key;
dataIndex?: string; // Note: We can not use generic type here, since we need to support nested key, see #9393 dataIndex?: string; // Note: We can not use generic type here, since we need to support nested key, see #9393
render?: (text: any, record: T, index: number) => React.ReactNode; render?: (text: any, record: T, index: number) => React.ReactNode;