Skip to content

react + antd表格自定义后端接口排序 #8

Description

@machao07

onChange方法获取分页、排序信息

<Table
    dataSource={list}
    columns={columns}
    rowKey="companyId"
    loading={loading}
    scroll={{ x: 1000 }}
    onChange={handleChange}
    pagination={{
        total: total,
        current: pageNum,
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal: (total) => `共 ${total} 条`,
    }}
/>
const handleChange = (pagination: TablePaginationConfig, filters: any, sorter: any) => {
    const sort = sorter.order === 'ascend' ? 'ASC' : 'DESC';
    this.form.current.validateFields().then((values: any) => {
        this.setState({
            sortList: [{ field: sorter.field ?? 'amount', sort }],
            pageNum: pagination.current ?? 1,
            pageSize: pagination.pageSize ?? 10
        }, () => {
            const { pageNum, pageSize, sortList } = this.state
            const { date, companyId, companyName, bankName, type } = values
            const beginDate = moment(date[0]).format('YYYY-MM-DD HH:mm:ss');
            const endDate = moment(date[1]).format('YYYY-MM-DD HH:mm:ss');
            this.queryList({ pageNum, pageSize, sortList, companyName, companyId, bankName, type: type && type.length ? type : undefined, beginDate, endDate });
        })
    })
}

console.log(pagination)

image

console.log(sorter)

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions