Need to add an input field to a table row
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?
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>)
}
}];
Closing for now.