0

Hello fellow programmers.

Im new to react and i am trying to Update data inside react-table table.

I want to update the data in a particular cell with an onClick() event

following is my code snippet for code reference

return (
    <div>
        <table {...getTableProps()} style={{ border: 'solid 1px blue' }}>
        <thead>
            {headerGroups.map(headerGroup => (
            <tr {...headerGroup.getHeaderGroupProps()}>
                {headerGroup.headers.map(column => (
                <th
                    {...column.getHeaderProps()}>
                    {column.render('Header')}
                </th>
                ))}
            </tr>
            ))}
        </thead>
        <tbody {...getTableBodyProps()}>
            {rows.map(row => {
            prepareRow(row)
            return (
                <tr {...row.getRowProps()}>
                {row.cells.map(cell => {
                    return (
                    <td
                        {...cell.getCellProps()} onClick={() => console.log(cell.value)} >
                        {cell.render('Cell')}
                    </td>
                    )
                })}
                </tr>
            )
            })}
        </tbody>
        </table>
10
  • please add some more details to your question, codeReview required , for a start add some screenShot or CodePlay for your problem Commented Mar 30, 2022 at 13:35
  • i have edited the question im new to stack overflow sorry mate. :D Commented Mar 30, 2022 at 13:38
  • noWorry's welcome to the club, now in regard to your problem , do you want to update values of cell ? Commented Mar 30, 2022 at 13:42
  • Yes like just a simple update like hardcoded saying the value of the cell is "" for example and with the render part so that it shows the new value fo the cell Commented Mar 30, 2022 at 13:43
  • can you share your onClick function snnippt ? Commented Mar 30, 2022 at 13:48

1 Answer 1

1

if you want to make the table editable > you can try with following example , its self explanatory in their official docs.. check if it can help

https://codesandbox.io/s/github/tannerlinsley/react-table/tree/v7/examples/editable-data?file=/src/App.js:6709-6714

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you my friend this worked beautifully!!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.