ant-design / pro-components

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

🐛[BUG] ProTable 中使用renderFormItem联动渲染Select失败,无法展示 #6361

Closed adw2022 closed 1 year ago

adw2022 commented 1 year ago

提问前先看看:

https://github.com/ryanhanwu/How-To-Ask-Questions-The-Smart-Way/blob/main/README-zh_CN.md

🐛 bug 描述

ProTable 中 通过renderFormItem动态渲染Select 失败,默认初始化渲染异常,切换无效果,重置按钮也不生效;如果将fieldProps.mode去除,Select单选模式下切换可以正常渲染,但是初始化及重置按钮还是无效

📷 复现步骤

https://codesandbox.io/s/protable-lian-dong-ce-shi-iddrlt?file=/App.tsx image

🏞 期望结果

表单渲染正常

💻 复现代码

import { ProTable } from "@ant-design/pro-components";
import React from "react";

export default () => {
  const columns = [
    {
      title: "状态",
      dataIndex: "status",
      hideInForm: true,
      valueType: "select",
      initialValue: false,
      fieldProps: {
        options: [
          {
            label: "Yes",
            value: true
          },
          {
            label: "No",
            value: false
          }
        ]
      }
    },
    {
      title: "color",
      sorter: true,
      dataIndex: "color",
      valueType: "select",
      fieldProps: {
        mode: "multiple",
        options: [
          {
            label: "blue",
            value: "blue"
          },
          {
            label: "black",
            value: "black"
          }
        ]
      },
      renderFormItem: (item, { defaultRender, ...rest }, form) => {
        const status = form.getFieldValue("status");

        if (status === false) {
          return false;
        }

        return defaultRender(item);
      }
    }
  ];
  return (
    <ProTable
      columns={columns}
      rowKey="key"
      options={false}
      dateFormatter="string"
      headerTitle="测试"
    />
  );
};

© 版本信息

github-actions[bot] commented 1 year ago

以下的 Issues 可能会帮助到你 / The following issues may help you

Duncan-MGH commented 1 year ago

哥 我现在也遇到这种情况 搜索框联动 主要想实现功能是清除前一个搜索框,它的后续搜索框清除已选择的选项,使用了renderFormItem也是一样的情况 请问你解决了吗

lovewinders commented 1 year ago

我也碰到类似color被联动字段无法隐藏问题,复现路径:切换联动表单->点击重置->切换联动表单->点击重置

chenshuai2144 commented 1 year ago

修复啦,多render了几次