ant-design / pro-components

🏆 Use Ant Design like a Pro!
https://pro-components.antdigital.dev
MIT License
4.23k stars 1.35k forks source link

👑 [需求]希望可以自定义sort排序字段 #2283

Closed birdycn closed 3 years ago

birdycn commented 3 years ago

现在是这么用的。。感觉有些别扭

    {
      dataIndex: 'serviceProductID',
      sorter: true,
      renderText: (v, r) => r?.serviceProduct?.name,
      search: { transform: (v) => ({ serviceProduct: v }) },
    }

期待用法

    {
      dataIndex: ["serviceProduct","name"],
      sorter: “serviceProductID”
    }
xiefengnian commented 3 years ago

sorter 支持传入一个函数,这样写能满足你的要求吗:

columns={[
  {
    title: 'Name',
    dataIndex: ['serviceProduct', 'name'],
    sorter: (a, b) => {
      return a.serviceProductID - b.serviceProductID;
    },
  },
]}
Nokecy commented 3 years ago

@birdycn 说的应该是服务端排序 ,

birdycn commented 3 years ago

@birdycn 说的应该是服务端排序 ,

sorter 支持传入一个函数,这样写能满足你的要求吗:

columns={[
  {
    title: 'Name',
    dataIndex: ['serviceProduct', 'name'],
    sorter: (a, b) => {
      return a.serviceProductID - b.serviceProductID;
    },
  },
]}

排序在服务端实现了,只是有些嵌套数组排序字段只能修改dataIndex,不太方便

shanzhaozhen commented 3 years ago

我也想获得这个效果,请问实现了吗,之前在使用element-ui是存在sort-by字段可以传入指定的排序字段,当该值存在可以跟dataIndex区分开,实现自定义排序,但是antdp实现不了,目前暂时的替代方案如下(偷换概念):

    {
      title: '员工编号',
      // dataIndex: 'staffCode',
      dataIndex: 's.staff_code',
      valueType: 'text',
      sorter: true,
      hideInSearch: true,
      renderText: (_, record) => record.staffCode,
    },

希望可以早点实现该效果,就不用多写个renderText

chenshuai2144 commented 3 years ago

sorter 支持一个方法的。

sorter:(a,b)=>a-b

shanzhaozhen commented 3 years ago

sorter 支持一个方法的。

sorter:(a,b)=>a-b

这个是前端分页,这边想结合protable中‘request’API中的sorter进行服务器分页