ANTD表选择不起作用,始终选择所有行

发布于 2025-01-22 01:00:16 字数 6071 浏览 2 评论 0原文

我正在尝试在我的ANTD表中实现行选择,但是当我选择所有行时,所有的行都会选择

 <PhcTable
                                pagination={false}
                                dataSource={configurationOptions?.ConfigDeposits[index].creditTiers}
                                columns={columnsPaymentPlans}
                                rowSelection={{onselect:(record)=>{console.log(record)}}}
                                scroll={{ x: 500 }}
                              />

const colunst colundspaymentplans = [

{
  title: "Credit Tiers",
  dataIndex: 'creditTier',
  key: 'creditTier',
  width: 80
},
{
  title: "Credit Risk",
  dataIndex: "CreditRisk",
  key: "CreditRisk",
  width: 60,
},
{
  title: "Notes",
  dataIndex: "notes",
  key: "notes",
  width: 100,
},
{
  title: "Deposit",
  dataIndex: "deposit",
  key: "deposit",
  width: 60,
  fixed: "right",
  render: (text, record, index) => (
    <PhcForm.Item
      initialValue={text}
      name={`deposit${record.providerSpecialtyId.toString()+index.toString()}`}
      rules={[
        { required: true, message: "Field is required" },
        {
          validator: (rule, value, callback) =>
            validateDeposit(rule, value, callback, record,"%"),
        },
      ]}
    >
      <PhcInputNumber
        maxLength={4}
        style={{
          height: "40px",
          width: isBrowser ? "75%" : "100%",
          padding: "4px 11px",
        }}            
        value={text}
        //onChange={onInputChange("minDepositType", index)}
      />
    </PhcForm.Item>
  ),
},
{
  title: "Max Loan Amount",
  dataIndex: "maxLoanAmount",
  key: "maxLoanAmount",
  width: 70,
  fixed: "right",
  render: (text, record, index) => (
    <PhcForm.Item
      initialValue={text}
      name={`maxLoanAmount${record.providerSpecialtyId.toString()+index.toString()}`}
      rules={[
        { required: true, message: "Field is required" },
        {
          validator: (rule, value, callback) =>
            validateMaxLoanAmount(rule, value, callback, record),
        },
      ]}
    >
      <PhcInputDecimal
        keyboard={true}
        controls={true}
        onKeyPress={onNumberPress}
        formatter={(value) =>
          `${value}`.replace(/(\..*)\./g, '$($1)')
        }
        maxLength={5}
        style={{
          height: "40px",
          //width: isBrowser && "75%",
          width: isBrowser ? "75%" : "100%",
          padding: "4px 11px",
          //minWidth: "218px",
        }}
        value={text}
        //onChange={onInputChange("maxLoanAmount", index)}
      />
    </PhcForm.Item>
  ),
},
{
  title: "Terms",
  dataIndex: "Terms",
  key: "configDepositsTermsIds",
  width: 150,
  render: (text, record, index) => (
    <PhcForm.Item
      initialValue={record.Terms.filter(x=>x.selected == true).map(x=>x.id)}
      name={`ConfigDepositsTermsIds${record.providerSpecialtyId.toString()+index.toString()}`}
      rules={[
        { required: true, message: "Field is required" },
        {
          validator: (rule, value, callback) =>
            validateDeposit(rule, value, callback, record),
        },
      ]}
    >
      <PhcSelect
        mode="multiple"
        optionFilterProp="label"
        allowClear
        showSearch
        showArrow
        style={{ width: isBrowser && "75%" }}
      >
        {record.Terms &&
          record.Terms.map((item) => (
            <PhcSelect.Option value={item.id} label={item.term}>
              {item.term}
            </PhcSelect.Option>
          ))}
      </PhcSelect>
    </PhcForm.Item>
  ),
}

];

“信贷”:[ { “ Providerspecialtyid”:1735, “ CredittierId”:1, “ Credittier”:“ Tier 1 Credit -Prime”, “ CreditRisk”:“低”, “笔记”:“这个信用层为接近赛,主要和超级赛事服务。”, “存款”:0, “ Maxloanamount”:20000, “选择”:false, “术语”:[ { “ id”:1, “术语”:“ 6”, “选择”:false },, { “ id”:2, “术语”:“ 12”, “选择”:false },, { “ id”:3, “术语”:“ 18”, “选择”:false },, { “ id”:4, “术语”:“ 24”, “选择”:false },, { “ id”:5, “术语”:“ 36”, “选择”:false },, { “ id”:6, “术语”:“ 48”, “选择”:false },, { “ id”:7, “术语”:“ 60”, “选择”:false } 这是给出的 },, { “ Providerspecialtyid”:1735, “ CredittierId”:2, “ Credittier”:“ Tier 2 Credit -sub -Prime”, “ CreditRisk”:“低/中等”, “笔记”:“此信用层也为低收入申请人提供服务。” “存款”:10, “ Maxloanamount”:20000, “选择”:false, “术语”:[ { “ id”:1, “术语”:“ 6”, “选择”:false },, { “ id”:2, “术语”:“ 12”, “选择”:false },, { “ id”:3, “术语”:“ 18”, “选择”:false },, { “ id”:4, “术语”:“ 24”, “选择”:false },, { “ id”:5, “术语”:“ 36”, “选择”:false },, { “ id”:6, “术语”:“ 48”, “选择”:false },, { “ id”:7, “术语”:“ 60”, “选择”:false } 这是给出的 },, { “ Providerspecialtyid”:1735, “ CredittierId”:3, “ Credittier”:“ Tier 3 Credit -Deep Sub -Prime”, “ CreditRisk”:“中/高”, “笔记”:“该信用层最好与正畸一起使用。”, “存款”:15, “ Maxloanamount”:15000, “选择”:false, “术语”:[ { “ id”:1, “术语”:“ 6”, “选择”:false },, { “ id”:2, “术语”:“ 12”, “选择”:false },, { “ id”:3, “术语”:“ 18”, “选择”:false },, { “ id”:4, “术语”:“ 24”, “选择”:false },, { “ id”:5, “术语”:“ 36”, “选择”:false },, { “ id”:6, “术语”:“ 48”, “选择”:false },, { “ id”:7, “术语”:“ 60”, “选择”:false } 这是给出的 },, { “ Providerspecialtyid”:1735, “ CredittierId”:4, “ Credittier”:“ Tier 4 Credit -Bendbanked”, “ CreditRisk”:“中/高”, “笔记”:“申请人可以使用SS#或ITIN#申请。” “存款”:15, “ Maxloanamount”:7500, “选择”:false, “术语”:[ { “ id”:1, “术语”:“ 6”, “选择”:false },, { “ id”:2, “术语”:“ 12”, “选择”:false },, { “ id”:3, “术语”:“ 18”, “选择”:false },, { “ id”:4, “术语”:“ 24”, “选择”:false },, { “ id”:5, “术语”:“ 36”, “选择”:false },, { “ id”:6, “术语”:“ 48”, “选择”:false },, { “ id”:7, “术语”:“ 60”, “选择”:false } 这是给出的 },, { “ Providerspecialtyid”:1735, “ CredittierId”:5, “ Credittier”:“ Tier 5 Credit -last Resort”, “ CreditRisk”:“高”, “笔记”:“将牙科还款选项限制为2、3和4个月。 “存款”:20, “ Maxloanamount”:7500, “选择”:false, “术语”:[ { “ id”:1, “术语”:“ 6”, “选择”:false },, { “ id”:2, “术语”:“ 12”, “选择”:false },, { “ id”:3, “术语”:“ 18”, “选择”:false },, { “ id”:4, “术语”:“ 24”, “选择”:false },, { “ id”:5, “术语”:“ 36”, “选择”:false },, { “ id”:6, “术语”:“ 48”, “选择”:false },, { “ id”:7, “术语”:“ 60”, “选择”:false } 这是给出的 } 这是给出的

I am trying to implement row selection in my antd table but when I am selecting any rows all the rows gets selected

 <PhcTable
                                pagination={false}
                                dataSource={configurationOptions?.ConfigDeposits[index].creditTiers}
                                columns={columnsPaymentPlans}
                                rowSelection={{onselect:(record)=>{console.log(record)}}}
                                scroll={{ x: 500 }}
                              />

const columnsPaymentPlans = [

{
  title: "Credit Tiers",
  dataIndex: 'creditTier',
  key: 'creditTier',
  width: 80
},
{
  title: "Credit Risk",
  dataIndex: "CreditRisk",
  key: "CreditRisk",
  width: 60,
},
{
  title: "Notes",
  dataIndex: "notes",
  key: "notes",
  width: 100,
},
{
  title: "Deposit",
  dataIndex: "deposit",
  key: "deposit",
  width: 60,
  fixed: "right",
  render: (text, record, index) => (
    <PhcForm.Item
      initialValue={text}
      name={`deposit${record.providerSpecialtyId.toString()+index.toString()}`}
      rules={[
        { required: true, message: "Field is required" },
        {
          validator: (rule, value, callback) =>
            validateDeposit(rule, value, callback, record,"%"),
        },
      ]}
    >
      <PhcInputNumber
        maxLength={4}
        style={{
          height: "40px",
          width: isBrowser ? "75%" : "100%",
          padding: "4px 11px",
        }}            
        value={text}
        //onChange={onInputChange("minDepositType", index)}
      />
    </PhcForm.Item>
  ),
},
{
  title: "Max Loan Amount",
  dataIndex: "maxLoanAmount",
  key: "maxLoanAmount",
  width: 70,
  fixed: "right",
  render: (text, record, index) => (
    <PhcForm.Item
      initialValue={text}
      name={`maxLoanAmount${record.providerSpecialtyId.toString()+index.toString()}`}
      rules={[
        { required: true, message: "Field is required" },
        {
          validator: (rule, value, callback) =>
            validateMaxLoanAmount(rule, value, callback, record),
        },
      ]}
    >
      <PhcInputDecimal
        keyboard={true}
        controls={true}
        onKeyPress={onNumberPress}
        formatter={(value) =>
          `${value}`.replace(/(\..*)\./g, '$($1)')
        }
        maxLength={5}
        style={{
          height: "40px",
          //width: isBrowser && "75%",
          width: isBrowser ? "75%" : "100%",
          padding: "4px 11px",
          //minWidth: "218px",
        }}
        value={text}
        //onChange={onInputChange("maxLoanAmount", index)}
      />
    </PhcForm.Item>
  ),
},
{
  title: "Terms",
  dataIndex: "Terms",
  key: "configDepositsTermsIds",
  width: 150,
  render: (text, record, index) => (
    <PhcForm.Item
      initialValue={record.Terms.filter(x=>x.selected == true).map(x=>x.id)}
      name={`ConfigDepositsTermsIds${record.providerSpecialtyId.toString()+index.toString()}`}
      rules={[
        { required: true, message: "Field is required" },
        {
          validator: (rule, value, callback) =>
            validateDeposit(rule, value, callback, record),
        },
      ]}
    >
      <PhcSelect
        mode="multiple"
        optionFilterProp="label"
        allowClear
        showSearch
        showArrow
        style={{ width: isBrowser && "75%" }}
      >
        {record.Terms &&
          record.Terms.map((item) => (
            <PhcSelect.Option value={item.id} label={item.term}>
              {item.term}
            </PhcSelect.Option>
          ))}
      </PhcSelect>
    </PhcForm.Item>
  ),
}

];

"creditTiers": [
{
"providerSpecialtyId": 1735,
"creditTierId": 1,
"creditTier": "Tier 1 Credit - Prime",
"CreditRisk": "Low",
"notes": "This credit tier serves near-prime, prime, and super-prime.",
"deposit": 0,
"maxLoanAmount": 20000,
"selected": false,
"Terms": [
{
"id": 1,
"term": "6",
"selected": false
},
{
"id": 2,
"term": "12",
"selected": false
},
{
"id": 3,
"term": "18",
"selected": false
},
{
"id": 4,
"term": "24",
"selected": false
},
{
"id": 5,
"term": "36",
"selected": false
},
{
"id": 6,
"term": "48",
"selected": false
},
{
"id": 7,
"term": "60",
"selected": false
}
]
},
{
"providerSpecialtyId": 1735,
"creditTierId": 2,
"creditTier": "Tier 2 Credit - Sub-Prime",
"CreditRisk": "Low/Moderate",
"notes": "This credit tier also serves low-income applicants.",
"deposit": 10,
"maxLoanAmount": 20000,
"selected": false,
"Terms": [
{
"id": 1,
"term": "6",
"selected": false
},
{
"id": 2,
"term": "12",
"selected": false
},
{
"id": 3,
"term": "18",
"selected": false
},
{
"id": 4,
"term": "24",
"selected": false
},
{
"id": 5,
"term": "36",
"selected": false
},
{
"id": 6,
"term": "48",
"selected": false
},
{
"id": 7,
"term": "60",
"selected": false
}
]
},
{
"providerSpecialtyId": 1735,
"creditTierId": 3,
"creditTier": "Tier 3 Credit - Deep Sub-Prime",
"CreditRisk": "Moderate/High",
"notes": "This credit tier is best used with orthodontics.",
"deposit": 15,
"maxLoanAmount": 15000,
"selected": false,
"Terms": [
{
"id": 1,
"term": "6",
"selected": false
},
{
"id": 2,
"term": "12",
"selected": false
},
{
"id": 3,
"term": "18",
"selected": false
},
{
"id": 4,
"term": "24",
"selected": false
},
{
"id": 5,
"term": "36",
"selected": false
},
{
"id": 6,
"term": "48",
"selected": false
},
{
"id": 7,
"term": "60",
"selected": false
}
]
},
{
"providerSpecialtyId": 1735,
"creditTierId": 4,
"creditTier": "Tier 4 Credit - Underbanked",
"CreditRisk": "Moderate/High",
"notes": "Applicants may use a SS# or an ITIN# to apply.",
"deposit": 15,
"maxLoanAmount": 7500,
"selected": false,
"Terms": [
{
"id": 1,
"term": "6",
"selected": false
},
{
"id": 2,
"term": "12",
"selected": false
},
{
"id": 3,
"term": "18",
"selected": false
},
{
"id": 4,
"term": "24",
"selected": false
},
{
"id": 5,
"term": "36",
"selected": false
},
{
"id": 6,
"term": "48",
"selected": false
},
{
"id": 7,
"term": "60",
"selected": false
}
]
},
{
"providerSpecialtyId": 1735,
"creditTierId": 5,
"creditTier": "Tier 5 Credit - Last Resort",
"CreditRisk": "High",
"notes": "Limits dental repayment options to 2, 3, and 4 months.",
"deposit": 20,
"maxLoanAmount": 7500,
"selected": false,
"Terms": [
{
"id": 1,
"term": "6",
"selected": false
},
{
"id": 2,
"term": "12",
"selected": false
},
{
"id": 3,
"term": "18",
"selected": false
},
{
"id": 4,
"term": "24",
"selected": false
},
{
"id": 5,
"term": "36",
"selected": false
},
{
"id": 6,
"term": "48",
"selected": false
},
{
"id": 7,
"term": "60",
"selected": false
}
]
}
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一人独醉 2025-01-29 01:00:16

问题是您没有为每行指定密钥。默认情况下,ANTD在每行中查找。由于您没有它,并且根据您上面添加的数据,因此密钥是credittierid。因此,您可以在表中指定行键:

rowkey = {(record)=&gt; rection.credittierid}

如果您只是启用rowselection,则可以选择任何行。但是,为了了解您选择的行,您可以创建一个状态并控制Rowselection。请检查代码。我在Rowselection中使用Onchange功能,并提供了两个参数。选定的行键的第一个数组&amp;第二个选择行。


function App() {
    const [selectedRowKeys, setSelectedRowKeys] = useState([]);

    const columnsPaymentPlans = [
        {
            title: 'Credit Tiers',
            dataIndex: 'creditTier',
            key: 'creditTier',
            width: 80
        },
        {
            title: 'Credit Risk',
            dataIndex: 'CreditRisk',
            key: 'CreditRisk',
            width: 60
        },
        {
            title: 'Notes',
            dataIndex: 'notes',
            key: 'notes',
            width: 100
        },
    // ...Other Columns
    ];

    return (
        <Table
            pagination={false}
            dataSource={configurationOptions?.creditTiers}
            columns={columnsPaymentPlans}
            rowKey={(record) => record.creditTierId}
            rowSelection={{
                selectedRowKeys,
                onChange: (selectedRowKeys, selectedRows) => {
                    setSelectedRowKeys(selectedRowKeys);
                }
            }}
            scroll={{ x: 500 }}
        />
    );
}

export default App;

The problem is that you didn't specify key for each row. By default, antd find key in each row. Since you don't have it and according to the data you added above, the key is creditTierId. So you can specify row key in table by:

rowKey={(record) => record.creditTierId}

If you just enable rowSelection, you can select any row. But in order to know the rows you have selected, you can create a state and control the rowSelection. Please check the code. I use onChange function in rowSelection and it provides two arguments. The first one array of selected Row keys & second one selected rows.


function App() {
    const [selectedRowKeys, setSelectedRowKeys] = useState([]);

    const columnsPaymentPlans = [
        {
            title: 'Credit Tiers',
            dataIndex: 'creditTier',
            key: 'creditTier',
            width: 80
        },
        {
            title: 'Credit Risk',
            dataIndex: 'CreditRisk',
            key: 'CreditRisk',
            width: 60
        },
        {
            title: 'Notes',
            dataIndex: 'notes',
            key: 'notes',
            width: 100
        },
    // ...Other Columns
    ];

    return (
        <Table
            pagination={false}
            dataSource={configurationOptions?.creditTiers}
            columns={columnsPaymentPlans}
            rowKey={(record) => record.creditTierId}
            rowSelection={{
                selectedRowKeys,
                onChange: (selectedRowKeys, selectedRows) => {
                    setSelectedRowKeys(selectedRowKeys);
                }
            }}
            scroll={{ x: 500 }}
        />
    );
}

export default App;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文