Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
passing data from antdesign table row to modal

I have a table in which each row has a button that would send a DELETE request to delete that row's data from database:

{
    title: '',
    render: (record) => {
        return (
            <Button icon={<DeleteOutlined />} style={{color:'#1890ff', border:'solid 0px'}} onClick={() => showModal(record)}
            >
            </Button>
        ) 
    }
},

Here I'm trying to pass the record data when clicking on the button to a modal. To do that I created a useState hook that would store my table row's data and then I wanted to pass the data to a modal:

const [modalTaskId, setModalTaskId] = useState();
const [visible, setVisible] = useState(false);
const showModal = (record) => {
    setModalTaskId(record);
    setVisible(true);

};

This is my modal:

<Modal
    visible={visible}
    onOk={() =>{handleOk()}}
    confirmLoading={confirmLoading}
    onCancel={handleCancel}
>
    <p>{modalText}</p>
</Modal>

And let's say I want to log the modalTaskId when clicking ok on modal:

const handleOk = async () => {
    console.log('modalTaskId: ', modalTaskId)
}

But it logs empty for me! So how can I pass data from my table's row to my modal and then use that data when clicking on modal's ok button?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Here's an example

Essentially, depending on the scope of your columns object, you can wrap them as a return value in a function that captures the context of your showModal handler.

const getColumns(showModal) { 
  return [{
    title: "Buttons", 
    dataIndex: 'arbitrary', 
    render: (text, record) => 
      <Button onClick={showModal}>Open Modal</Button>
  }, ...]
}

...

// Usage
<Table dataSource={dataSource} columns={getColumns(showModal)} />

Note that this may not be the most performant solution.

about 4 years ago · Juan Pablo Isaza Relatório

0

At the first, set the Initial value for your modalTaskId.

const [modalTaskId, setModalTaskId] = useState();

Then, remove onOk, You can control your visibility by useEffect:

useEffect(() => {
    if (visible) console.log(modalTaskId);
}, [visible])
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda