Skip to content

Commit

Permalink
Perfect fix # 744
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jan 23, 2018
1 parent 99f9e59 commit b4fd0e0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/routes/Forms/TableForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React, { PureComponent } from 'react';
import Debounce from 'lodash-decorators/debounce';
import Bind from 'lodash-decorators/bind';
import { Table, Button, Input, message, Popconfirm, Divider } from 'antd';
import styles from './style.less';

Expand All @@ -10,6 +8,7 @@ export default class TableForm extends PureComponent {

this.state = {
data: props.value,
loading: false,
};
}
componentWillReceiveProps(nextProps) {
Expand All @@ -35,9 +34,7 @@ export default class TableForm extends PureComponent {
}
});
}
@Bind()
@Debounce(400)
toggleEditable(e, key) {
toggleEditable=(e, key) => {
e.preventDefault();
const newData = this.state.data.map(item => ({ ...item }));
const target = this.getRowByKey(key, newData);
Expand Down Expand Up @@ -83,6 +80,9 @@ export default class TableForm extends PureComponent {
}
saveRow(e, key) {
e.persist();
this.setState({
loading: true,
});
// save field when blur input
setTimeout(() => {
if (document.activeElement.tagName === 'INPUT' &&
Expand All @@ -102,7 +102,10 @@ export default class TableForm extends PureComponent {
delete target.isNew;
this.toggleEditable(e, key);
this.props.onChange(this.state.data);
}, 10);
this.setState({
loading: false,
});
}, 500);
}
cancel(e, key) {
this.clickedCancel = true;
Expand Down Expand Up @@ -179,6 +182,9 @@ export default class TableForm extends PureComponent {
title: 'ζ“δ½œ',
key: 'action',
render: (text, record) => {
if (!!record.editable && this.state.loading) {
return null;
}
if (record.editable) {
if (record.isNew) {
return (
Expand Down Expand Up @@ -214,6 +220,7 @@ export default class TableForm extends PureComponent {
return (
<div>
<Table
loading={this.state.loading}
columns={columns}
dataSource={this.state.data}
pagination={false}
Expand Down

0 comments on commit b4fd0e0

Please sign in to comment.