mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
parent
4635b60da0
commit
a11913c49a
@ -38,9 +38,28 @@ const columns = [{
|
|||||||
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
<BootstrapTable keyField='id' data={ products } columns={ columns } />
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default () => (
|
export default class Test extends React.Component {
|
||||||
<div>
|
constructor(props) {
|
||||||
<BootstrapTable keyField="id" data={ products } columns={ columns } />
|
super(props);
|
||||||
<Code>{ sourceCode }</Code>
|
this.state = { data: products };
|
||||||
</div>
|
}
|
||||||
);
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -39,12 +39,10 @@ export default Base =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if (nextProps.isDataChanged) {
|
const sortedColumn = nextProps.columns.find(
|
||||||
const sortedColumn = nextProps.columns.find(
|
column => column.dataField === nextProps.store.sortField);
|
||||||
column => column.dataField === nextProps.store.sortField);
|
if (sortedColumn && sortedColumn.sort) {
|
||||||
if (sortedColumn) {
|
nextProps.store.sortBy(sortedColumn);
|
||||||
nextProps.store.sortBy(sortedColumn);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -219,30 +219,12 @@ describe('SortWrapper', () => {
|
|||||||
nextProps = { columns, store };
|
nextProps = { columns, store };
|
||||||
store.sortField = columns[1].dataField;
|
store.sortField = columns[1].dataField;
|
||||||
store.sortOrder = Const.SORT_DESC;
|
store.sortOrder = Const.SORT_DESC;
|
||||||
|
store.sortBy = sinon.stub();
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('if nextProps.isDataChanged is true', () => {
|
it('should sorting again', () => {
|
||||||
beforeEach(() => {
|
wrapper.instance().componentWillReceiveProps(nextProps);
|
||||||
nextProps.isDataChanged = true;
|
expect(store.sortBy.calledOnce).toBeTruthy();
|
||||||
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user