table icon indicating copy to clipboard operation
table copied to clipboard

Need to add an input field to a table row

Open aree5741 opened this issue 9 years ago • 2 comments

What is the proper way to add an input field to a table row and get the typed value within the input field when selecting the row?

aree5741 avatar Mar 14 '17 05:03 aree5741

just use the render: (row, rowValue, index) => () property in the column that you want to show the input, you can even do a state tracking type of onClick event to switch from a <span /> to an <input /> tag and if you are using controlled inputs then an onChange on the <input> tag would update state and you can then grab it from state whenever you need it. Or use ref's and an onClick handler on a button attached to the input (or use enter keypress).

see here ...

edit: (i didnt test this code but something like this could work)

// ... removed for brevity
const handleClick = (e, row, index) => {
  e.preventDefault();
  // ... handle state change based on click
};
// ... removed for brevity

const columns = [{
  header: 'Field 1',
  id: 'field-1',
  render: (row, rowValue, index) => {
    // you could probably do this a bit cleaner and avoid duplicate returns with a let output = (); but meh this works too
    (this.state.isClicked)
      ? return (<input type="text" ref="input-field-1" />)
      : return (<span onClick={(e) => this.handleClick(e, row, index); }>{row.description}</span>)
  }
}];

mikedevita avatar Mar 14 '17 17:03 mikedevita

Closing for now.

tannerlinsley avatar Mar 27 '17 20:03 tannerlinsley