Remote Cell Edit cannot exit edit mode
Hi Allen, I am trying to implement Remote Cell Edit (for easier access to my database) with a customized cell editRenderer (to add a Save and Cancel Button to it). My problem is that the cell never exit edit mode after I click Save or Cancel or anywhere outside the table. The only way to end the state is to click on another editable cell. Normally without Remote, I can simply quit by calling editorProps.onUpdate to finish the cell editing process, but now I am kind of stuck here. Am I using it the wrong way that these two should not be used together? Or is there a way to make this work?
THanks!
@zike-Q firstly, I'm pretty sorry for lately reply. About your question, would you please share some code to me? I just try on my local and it's work, thanks.
Following is just some code to test custom editor in remote mode:
A custom editor:
class QualityRanger extends React.Component {
static propTypes = {
value: PropTypes.number,
onUpdate: PropTypes.func.isRequired
}
static defaultProps = {
value: 0
}
getValue() {
return parseInt(this.range.value, 10);
}
render() {
const { value, onUpdate, ...rest } = this.props;
return [
<input
{ ...rest }
key="range"
ref={ node => this.range = node }
type="range"
min="0"
max="30000"
/>,
<button
key="submit"
className="btn btn-default"
onClick={ () => onUpdate(this.getValue()) }
>
done
</button>
];
}
}
Table:
const cellEdit = {
mode: 'click',
blurToSave: true
};
return (
<div>
<BootstrapTable
remote={ { cellEdit: true } }
keyField="id"
data={ props.data }
columns={ columns }
cellEdit={ cellEditFactory(cellEdit) }
onTableChange={ props.onTableChange }
/>
<Code>{ sourceCode }</Code>
</div>
);
How to handle the remote(Just a settimeout to simulate the delay for api calling)
handleTableChange = (type, { data, cellEdit: { rowId, dataField, newValue } }) => {
console.log(newValue);
setTimeout(() => {
// handle update date here
const result = data.map((row) => {
if (row.id === rowId) {
const newRow = { ...row };
newRow[dataField] = newValue;
return newRow;
}
return row;
});
this.setState(() => ({
data: result
}));
}, 2000);
}
Hi, thanks for the reply. I re-wrote that part in the exact way as the example remote code and it worked, I was not sure what went wrong though.
In the earlier version, I did not have a separate const RemoteCellEdit to render handleTableChange() function. Could this be the problem?
was:
class AtomHistoryTable extends React.Component {
componentDidMount() {
// get data with API call
}
handleTableChange = (type, { data, cellEdit: { rowId, dataField, newValue } }) => {
// handle change
}
render() {
return (
<div>
<BootstrapTable
keyField='id'
data={atomChoices}
columns={columns}
cellEdit={ cellEditFactory(cellEditProp) }
</div>
);
}
}
Then:
const cellEdit = {... return <BootstrapTable />}
class AtomHistoryTable extends React.Component {
componentDidMount() {...}
handleTableChange = (type, { data, cellEdit: { rowId, dataField, newValue } }) => {
// handle change
}
render() {
return (
<div>
<RemoteCellEdit
data={ this.state.data }
errorMessage={ this.state.errorMessage }
onTableChange={ this.handleTableChange }
/>
</div>
);
}
}
@zike-Q I dont think so. But if there's a significant evidence, I will look into it deeply, thanks 👍
pagination time Cannot read properties of undefined (reading 'rowId') error showing
fixed. use like this