Click Edit in the form (in the form is a table), each column of this line becomes an input, editor, you always enter it backwards (for example: 1234, but the input is 4321). How to solve this problem?
cacheOriginData = {};
toggleEditable=(e, key) => {
e.preventDefault();
const newData = this.state.data_form.map(item => ({ ...item }));
const target = this.getRowByKey(key, newData);
if(target){
if(!target.editable){
this.cacheOriginData[key] = { ...target };
}
console.log("edit", newData, key)
target.editable = !target.editable;
this.setState({ data_form: newData });
}
}
handleFieldChange(e, fieldName, key) {
const newData = this.state.data_form.map(item => ({ ...item }));
const target = this.getRowByKey(key, newData);
console.log("onChange", e, newData, target, fieldName)
if (target) {
target[fieldName] = e.target.value;
this.setState({ data_form: newData });
}
}
const clumn = [
{
key: "time",
title: "",
dataIndex: "time",
width: 100,
render: (text, record) => {
if(record.editable){
return(
<Input defaultValue={text}
onChange={e => this.handleFieldChange(e, "time", record.key)}
autoFocus
placeholder=""/>
);
}
return text;
},
},
{
title: "",
dataIndex: "action",
width: 60,
render: (text, record) => {
console.log("render", !!record.editable)
if (record.editable) {
return (
<span>
<a onClick={e => this.saveRow(e, record.key)}></a>
<Divider type="vertical" />
<a onClick={e => this.cancel(e, record.key)}></a>
</span>
);
}
return (
<span>
<a onClick={e => this.toggleEditable(e, record.key)}></a>
<Divider type="vertical" />
<a onClick={this.removeRow.bind(this, record.key)} style={{color:"red"}}>
<Icon style={{ fontSize: 16}} type="delete" />
</a>
</span>
);
}}]