This commit is contained in:
Allen 2018-03-04 16:21:10 +08:00 committed by GitHub
parent 4635b60da0
commit a11913c49a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 34 deletions

View File

@ -38,9 +38,28 @@ const columns = [{
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`;
export default () => (
export default class Test extends React.Component {
constructor(props) {
super(props);
this.state = { data: products };
}
handleClick = () => {
this.setState(() => {
const newProducts = productsGenerator(21);
return {
data: newProducts
};
});
}
render() {
return (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } />
<button className="btn btn-default" onClick={ this.handleClick }>Change Data</button>
<BootstrapTable keyField="id" data={ this.state.data } columns={ columns } />
<Code>{ sourceCode }</Code>
</div>
);
);
}
}

View File

@ -39,14 +39,12 @@ export default Base =>
}
componentWillReceiveProps(nextProps) {
if (nextProps.isDataChanged) {
const sortedColumn = nextProps.columns.find(
column => column.dataField === nextProps.store.sortField);
if (sortedColumn) {
if (sortedColumn && sortedColumn.sort) {
nextProps.store.sortBy(sortedColumn);
}
}
}
handleSort(column) {
const { store } = this.props;

View File

@ -219,11 +219,6 @@ describe('SortWrapper', () => {
nextProps = { columns, store };
store.sortField = columns[1].dataField;
store.sortOrder = Const.SORT_DESC;
});
describe('if nextProps.isDataChanged is true', () => {
beforeEach(() => {
nextProps.isDataChanged = true;
store.sortBy = sinon.stub();
});
@ -232,17 +227,4 @@ describe('SortWrapper', () => {
expect(store.sortBy.calledOnce).toBeTruthy();
});
});
describe('if nextProps.isDataChanged is false', () => {
beforeEach(() => {
nextProps.isDataChanged = false;
store.sortBy = sinon.stub();
});
it('should not sorting', () => {
wrapper.instance().componentWillReceiveProps(nextProps);
expect(store.sortBy.calledOnce).toBeFalsy();
});
});
});
});