mirror of
https://gitee.com/baidu/amis.git
synced 2024-11-29 18:48:45 +08:00
chore: Table2排序属性名称变更order => orderDir (#7188)
This commit is contained in:
parent
a3802d8327
commit
ff0514e8d4
@ -17,13 +17,13 @@ import {ColumnProps} from './index';
|
||||
|
||||
export interface Props extends ThemeProps, LocaleProps {
|
||||
column: ColumnProps;
|
||||
onSort?: Function;
|
||||
onSort?: (payload: {orderBy: string; orderDir: string}) => any;
|
||||
active?: boolean;
|
||||
classnames: ClassNamesFn;
|
||||
}
|
||||
|
||||
export interface State {
|
||||
order: string; // 升序还是降序
|
||||
orderDir: string; // 升序还是降序
|
||||
orderBy: string; // 一次只能按一列排序 当前列的key
|
||||
}
|
||||
|
||||
@ -32,7 +32,7 @@ export class HeadCellSort extends React.Component<Props, State> {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
order: '',
|
||||
orderDir: '',
|
||||
orderBy: ''
|
||||
};
|
||||
}
|
||||
@ -45,7 +45,7 @@ export class HeadCellSort extends React.Component<Props, State> {
|
||||
!props?.active &&
|
||||
props.active !== prevProps?.active
|
||||
) {
|
||||
this.setState({orderBy: '', order: ''});
|
||||
this.setState({orderBy: '', orderDir: ''});
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,26 +58,27 @@ export class HeadCellSort extends React.Component<Props, State> {
|
||||
onClick={async () => {
|
||||
let sortPayload: State = {
|
||||
orderBy: '',
|
||||
order: ''
|
||||
orderDir: ''
|
||||
};
|
||||
if (column.name === this.state.orderBy) {
|
||||
if (this.state.order === 'desc') {
|
||||
if (this.state.orderDir === 'desc') {
|
||||
// 降序改为取消
|
||||
sortPayload = {orderBy: '', order: ''};
|
||||
sortPayload = {orderBy: '', orderDir: ''};
|
||||
} else {
|
||||
// 升序之后降序
|
||||
sortPayload = {orderBy: column.name, order: 'desc'};
|
||||
sortPayload = {orderBy: column.name, orderDir: 'desc'};
|
||||
}
|
||||
} else {
|
||||
// 默认先升序
|
||||
sortPayload = {orderBy: column.name, order: 'asc'};
|
||||
sortPayload = {orderBy: column.name, orderDir: 'asc'};
|
||||
}
|
||||
|
||||
if (onSort) {
|
||||
const prevented = await onSort({
|
||||
orderBy: sortPayload.orderBy,
|
||||
order: sortPayload.order
|
||||
orderDir: sortPayload.orderDir
|
||||
});
|
||||
|
||||
if (prevented) {
|
||||
return;
|
||||
}
|
||||
@ -89,7 +90,7 @@ export class HeadCellSort extends React.Component<Props, State> {
|
||||
<i
|
||||
className={cx(
|
||||
'TableCell-sortBtn--down',
|
||||
active && this.state.order === 'desc' ? 'is-active' : ''
|
||||
active && this.state.orderDir === 'desc' ? 'is-active' : ''
|
||||
)}
|
||||
>
|
||||
<Icon
|
||||
@ -101,7 +102,7 @@ export class HeadCellSort extends React.Component<Props, State> {
|
||||
<i
|
||||
className={cx(
|
||||
'TableCell-sortBtn--up',
|
||||
active && this.state.order === 'asc' ? 'is-active' : ''
|
||||
active && this.state.orderDir === 'asc' ? 'is-active' : ''
|
||||
)}
|
||||
>
|
||||
<Icon icon="sort-asc" className="icon" iconContent="table-sort-up" />
|
||||
|
@ -114,7 +114,7 @@ export interface OnRowProps {
|
||||
|
||||
export interface SortProps {
|
||||
orderBy: string;
|
||||
order: string;
|
||||
orderDir: string;
|
||||
}
|
||||
|
||||
export interface TableProps extends ThemeProps, LocaleProps, SpinnerExtraProps {
|
||||
|
@ -413,7 +413,7 @@ export interface Table2Props extends RendererProps, SpinnerExtraProps {
|
||||
onSaveOrder?: Function;
|
||||
onPristineChange?: Function;
|
||||
onAction?: Function;
|
||||
onSort?: Function;
|
||||
onSort?: (payload: {orderBy: string; orderDir: string}) => void;
|
||||
onSearch?: Function;
|
||||
onRow?: OnRowProps;
|
||||
placeholder?: string | SchemaObject;
|
||||
@ -1157,7 +1157,7 @@ export default class Table2 extends React.Component<Table2Props, object> {
|
||||
'columnSort',
|
||||
createObject(data, {
|
||||
orderBy: payload.orderBy,
|
||||
orderDir: payload.order
|
||||
orderDir: payload.orderDir
|
||||
})
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user