You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Antd Table含Select组件列的选中值排序问题求助

问题:Antd Table含下拉框的列无法按选中选项名称排序

我使用Antd Table渲染数据,将select作为单元格内容,当前以Id作为dataIndex渲染Select选项,但无法基于选中选项名称对该列进行排序。

代码示例

export const compareStrings = (a, b) =>
  a?.toString()?.localeCompare(b, undefined, { sensitivity: 'accent' });

const BTable = ({ tableId }) => {
  const COLUMNS = [
    {
      title: 'Utility Type',
      dataIndex: 'utilityTypeId',
      sorter: (a, b) => {
        const aname = a.utilityTypeId.props.options.find(
          (sm) => sm.utilityTypeId === a.utilityTypeId.props.name
        )?.name;
        const bname = b.utilityTypeId.props.options.find(
          (sm) => sm.utilityTypeId === a.utilityTypeId.props.name
        )?.name;
        return compareStrings(aname, bname);
      }
    },
    {
      title: 'Enduse Type',
      dataIndex: 'enduseTypeId'
    }
  ];
  
  return (
    <FieldArray name={tableId}>
      {({ fields }) => {
        const data = fields.map((name, index) => {
          return {
            rowKey: index,
            enduseTypeId: (
              <Field
                name={`${name}.enduseTypeId`}
                component={AntdSelectIdAdapter}
                options={enduseTypesData?.enduseTypes}
                render={(o) => o.name}
              />
            ),
            utilityTypeId: (
              <Field
                name={`${name}.utilityTypeId`}
                component={AntdSelectIdAdapter}
                options={utilityTypesData?.utilityTypes}
                render={(o) => o.name}
              />
            ),
          };
        });
        return (
          <Table
            dataSource={data}
            columns={COLUMNS}         
            rowKey="rowKey"                      
          />
        );
      }}
    </FieldArray>
  );
};

更新:我已尝试相关排序方法,但未生效。

恳请告知如何实现含下拉框的列按选中值排序,如需更多信息请告知。

内容的提问来源于stack exchange,提问作者kumar425

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 11:35:28