Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Table with one row ignoring number of columns

I want to create a table where the rows are clickable. When a row is clicked, I want to show input fields.

https://codesandbox.io/s/crazy-mountain-oye5rw?file=/src/App.js

For now just assume the word "test" is the input fields. I want to show/hide depending on row click

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Table

>Solution :

For row click you need to add click event handler for each row like,

<tr key={el.id} data-rowid={el.id} onClick={() => { showInputHandler(el.id) }}>

Then you need to check the selected id and store it in the state like,

  const showInputHandler = (id) => {
    setShowInput((prev) => {
      if (prev === id) {
        return;
      }
      return id;
    });
  };

Then add condition to display the input,

{showInput === el.id && <div>Some input</div>}

Forked Sandbox:

Edit exciting-dubinsky-ed9519

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading