Skip to content
Prev Previous commit
Next Next commit
fix #210 (#232)
  • Loading branch information
AllenFang authored Mar 4, 2018
commit a11913c49a10b80a31c35a2c2b02e075b8ed3e61
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,28 @@ const columns = [{
<BootstrapTable keyField='id' data={ products } columns={ columns } />
`;

export default () => (
<div>
<BootstrapTable keyField="id" data={ products } columns={ columns } />
<Code>{ sourceCode }</Code>
</div>
);
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>
<button className="btn btn-default" onClick={ this.handleClick }>Change Data</button>
<BootstrapTable keyField="id" data={ this.state.data } columns={ columns } />
<Code>{ sourceCode }</Code>
</div>
);
}
}
10 changes: 4 additions & 6 deletions packages/react-bootstrap-table2/src/sort/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ export default Base =>
}

componentWillReceiveProps(nextProps) {
if (nextProps.isDataChanged) {
const sortedColumn = nextProps.columns.find(
column => column.dataField === nextProps.store.sortField);
if (sortedColumn) {
nextProps.store.sortBy(sortedColumn);
}
const sortedColumn = nextProps.columns.find(
column => column.dataField === nextProps.store.sortField);
if (sortedColumn && sortedColumn.sort) {
nextProps.store.sortBy(sortedColumn);
}
}

Expand Down
26 changes: 4 additions & 22 deletions packages/react-bootstrap-table2/test/sort/wrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,30 +219,12 @@ describe('SortWrapper', () => {
nextProps = { columns, store };
store.sortField = columns[1].dataField;
store.sortOrder = Const.SORT_DESC;
store.sortBy = sinon.stub();
});

describe('if nextProps.isDataChanged is true', () => {
beforeEach(() => {
nextProps.isDataChanged = true;
store.sortBy = sinon.stub();
});

it('should sorting again', () => {
wrapper.instance().componentWillReceiveProps(nextProps);
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();
});
it('should sorting again', () => {
wrapper.instance().componentWillReceiveProps(nextProps);
expect(store.sortBy.calledOnce).toBeTruthy();
});
});
});