mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 03:29:39 +08:00
parent
26936de2e8
commit
68ad468938
@ -26,6 +26,7 @@ import {
|
|||||||
TableComponents,
|
TableComponents,
|
||||||
RowSelectionType,
|
RowSelectionType,
|
||||||
TableLocale,
|
TableLocale,
|
||||||
|
AdditionalCellProps,
|
||||||
ColumnProps,
|
ColumnProps,
|
||||||
CompareFn,
|
CompareFn,
|
||||||
TableStateFilters,
|
TableStateFilters,
|
||||||
@ -805,6 +806,7 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
|||||||
const key = this.getColumnKey(column, i) as string;
|
const key = this.getColumnKey(column, i) as string;
|
||||||
let filterDropdown;
|
let filterDropdown;
|
||||||
let sortButton;
|
let sortButton;
|
||||||
|
let onHeaderCell = column.onHeaderCell;
|
||||||
const sortTitle = this.getColumnTitle(column.title, {}) || locale.sortTitle;
|
const sortTitle = this.getColumnTitle(column.title, {}) || locale.sortTitle;
|
||||||
const isSortColumn = this.isSortColumn(column);
|
const isSortColumn = this.isSortColumn(column);
|
||||||
if ((column.filters && column.filters.length > 0) || column.filterDropdown) {
|
if ((column.filters && column.filters.length > 0) || column.filterDropdown) {
|
||||||
@ -839,8 +841,27 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
onHeaderCell = (col: Column<T>) => {
|
||||||
|
let colProps: AdditionalCellProps = {};
|
||||||
|
// Get original first
|
||||||
|
if (column.onHeaderCell) {
|
||||||
|
colProps = {
|
||||||
|
...column.onHeaderCell(col),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Add sorter logic
|
||||||
|
const onHeaderCellClick = colProps.onClick;
|
||||||
|
colProps.onClick = (...args) => {
|
||||||
|
this.toggleSortOrder(column);
|
||||||
|
if (onHeaderCellClick) {
|
||||||
|
onHeaderCellClick(...args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return colProps;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const sortTitleString = (sortButton && typeof sortTitle === 'string') ? sortTitle : undefined;
|
const sortTitleString = sortButton && typeof sortTitle === 'string' ? sortTitle : undefined;
|
||||||
return {
|
return {
|
||||||
...column,
|
...column,
|
||||||
className: classNames(column.className, {
|
className: classNames(column.className, {
|
||||||
@ -854,13 +875,13 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
|||||||
key="title"
|
key="title"
|
||||||
title={sortTitleString}
|
title={sortTitleString}
|
||||||
className={sortButton ? `${prefixCls}-column-sorters` : undefined}
|
className={sortButton ? `${prefixCls}-column-sorters` : undefined}
|
||||||
onClick={() => this.toggleSortOrder(column)}
|
|
||||||
>
|
>
|
||||||
{this.renderColumnTitle(column.title)}
|
{this.renderColumnTitle(column.title)}
|
||||||
{sortButton}
|
{sortButton}
|
||||||
</div>,
|
</div>,
|
||||||
filterDropdown,
|
filterDropdown,
|
||||||
],
|
],
|
||||||
|
onHeaderCell,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,11 @@ export interface ColumnProps<T> {
|
|||||||
onHeaderCell?: (props: ColumnProps<T>) => any;
|
onHeaderCell?: (props: ColumnProps<T>) => any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AdditionalCellProps {
|
||||||
|
onClick?: React.MouseEventHandler<HTMLElement>;
|
||||||
|
[name: string]: any;
|
||||||
|
}
|
||||||
|
|
||||||
export interface TableComponents {
|
export interface TableComponents {
|
||||||
table?: React.ReactType;
|
table?: React.ReactType;
|
||||||
header?: {
|
header?: {
|
||||||
|
Loading…
Reference in New Issue
Block a user