查询某个功能记录可点击某列进行排序,使用 ant 中的 a-tabel 组件。首先新建表格,在表格中声明change事件。

 <a-table
      ref="table"
      :alert="true"
      :columns="columns"
      :data-source="data"
      @change="handleChange"
      :scroll="{y: 500}"
      size="default"
    ></table>

列在 computed 函数里声明:

computed: {
    columns() {
      let { sortedInfo, filteredInfo } = this
      sortedInfo = sortedInfo || {}
      filteredInfo = filteredInfo || {}
      const columns = [
        {
          title: '金额',
          dataIndex: 'settlementAmount',
          customRender: text => moneyFormat(text),
          filteredValue: filteredInfo.settlementAmount || null,
          onFilter: (value, record) => record.settlementAmount.includes(value),
          sorter: (a, b) => a.settlementAmount.length - b.settlementAmount.length,
          sortOrder: sortedInfo.columnKey === 'settlementAmount' && sortedInfo.order,
          ellipsis: true
         }...
      ]
      return columns
    }
  }

这里涉及到了分页,所以每次排序我都会调用API再次获取数据,如果只是当前页进行排序,就不用调用了。

handleChange(pagination, filters, sorter) {
      console.log('Various parameters', pagination, filters, sorter)
      this.filteredInfo = filters
      this.sortedInfo = sorter
      if (sorter.order) {
        this.queryParam.orderByColumn = sorter.columnKey
        this.queryParam.isAsc = sorter.order === 'ascend' ? 'asc' : 'desc'
      }
      //调用后台api...
    },

ascend代表升序,descend代表降序在这里插入图片描述

Logo

前往低代码交流专区

更多推荐