Skip to content

Commit 6893be6

Browse files
committed
fix #975
1 parent 1800a52 commit 6893be6

File tree

5 files changed

+86
-27
lines changed

5 files changed

+86
-27
lines changed

src/BootstrapTable.js

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class BootstrapTable extends Component {
4646
currPage: currPage,
4747
expanding: this.props.options.expanding || [],
4848
sizePerPage: this.props.options.sizePerPage || Const.SIZE_PER_PAGE_LIST[0],
49-
selectedRowKeys: this.store.getSelectedRowKeys()
49+
selectedRowKeys: this.store.getSelectedRowKeys(),
50+
reset: false
5051
};
5152
}
5253

@@ -172,6 +173,18 @@ class BootstrapTable extends Component {
172173
});
173174
}
174175

176+
reset() {
177+
this.store.clean();
178+
this.setState({
179+
data: this.getTableData(),
180+
currPage: 1,
181+
expanding: [],
182+
sizePerPage: Const.SIZE_PER_PAGE_LIST[0],
183+
selectedRowKeys: this.store.getSelectedRowKeys(),
184+
reset: true
185+
});
186+
}
187+
175188
componentWillReceiveProps(nextProps) {
176189
this.initTable(nextProps);
177190
const { options, selectRow } = nextProps;
@@ -193,7 +206,8 @@ class BootstrapTable extends Component {
193206
this.setState({
194207
data: nextProps.data.slice(),
195208
currPage: page,
196-
sizePerPage
209+
sizePerPage,
210+
reset: false
197211
});
198212
} else {
199213
// #125
@@ -214,7 +228,8 @@ class BootstrapTable extends Component {
214228
this.setState({
215229
data,
216230
currPage: page,
217-
sizePerPage
231+
sizePerPage,
232+
reset: false
218233
});
219234
}
220235

@@ -223,7 +238,8 @@ class BootstrapTable extends Component {
223238
const copy = selectRow.selected.slice();
224239
this.store.setSelectedRowKey(copy);
225240
this.setState({
226-
selectedRowKeys: copy
241+
selectedRowKeys: copy,
242+
reset: false
227243
});
228244
}
229245
}
@@ -314,7 +330,8 @@ class BootstrapTable extends Component {
314330
bordered={ this.props.bordered }
315331
condensed={ this.props.condensed }
316332
isFiltered={ this.filter ? true : false }
317-
isSelectAll={ isSelectAll }>
333+
isSelectAll={ isSelectAll }
334+
reset={ this.state.reset }>
318335
{ this.props.children }
319336
</TableHeader>
320337
<TableBody ref='body'
@@ -384,7 +401,8 @@ class BootstrapTable extends Component {
384401
cleanSelected() {
385402
this.store.setSelectedRowKey([]);
386403
this.setState({
387-
selectedRowKeys: []
404+
selectedRowKeys: [],
405+
reset: false
388406
});
389407
}
390408

@@ -399,12 +417,13 @@ class BootstrapTable extends Component {
399417

400418
const result = this.store.sort().get();
401419
this.setState({
402-
data: result
420+
data: result,
421+
reset: false
403422
});
404423
}
405424

406425
handleExpandRow = expanding => {
407-
this.setState({ expanding }, () => {
426+
this.setState({ expanding, reset: false }, () => {
408427
this._adjustHeaderWidth();
409428
});
410429
}
@@ -417,7 +436,8 @@ class BootstrapTable extends Component {
417436

418437
this.setState({
419438
currPage: page,
420-
sizePerPage
439+
sizePerPage,
440+
reset: false
421441
});
422442

423443
if (this.isRemoteDataSource()) {
@@ -436,7 +456,7 @@ class BootstrapTable extends Component {
436456

437457
const result = this.store.page(normalizedPage, sizePerPage).get();
438458

439-
this.setState({ data: result });
459+
this.setState({ data: result, reset: false });
440460
}
441461

442462
handleMouseLeave = () => {
@@ -512,7 +532,7 @@ class BootstrapTable extends Component {
512532
}
513533

514534
this.store.setSelectedRowKey(selectedRowKeys);
515-
this.setState({ selectedRowKeys });
535+
this.setState({ selectedRowKeys, reset: false });
516536
}
517537
}
518538

@@ -526,6 +546,7 @@ class BootstrapTable extends Component {
526546
}
527547
this.setState({
528548
data: result,
549+
reset: false,
529550
currPage: this.props.options.pageStartIndex || Const.PAGE_START_INDEX
530551
});
531552
}
@@ -552,7 +573,8 @@ class BootstrapTable extends Component {
552573

553574
this.store.setSelectedRowKey(currSelected);
554575
this.setState({
555-
selectedRowKeys: currSelected
576+
selectedRowKeys: currSelected,
577+
reset: false
556578
});
557579
}
558580
}
@@ -567,7 +589,8 @@ class BootstrapTable extends Component {
567589
const isValid = beforeSaveCell(this.state.data[rowIndex], fieldName, newVal);
568590
if (!isValid && typeof isValid !== 'undefined') {
569591
this.setState({
570-
data: this.store.get()
592+
data: this.store.get(),
593+
reset: false
571594
});
572595
return;
573596
}
@@ -586,7 +609,8 @@ class BootstrapTable extends Component {
586609

587610
const result = this.store.edit(newVal, rowIndex, fieldName).get();
588611
this.setState({
589-
data: result
612+
data: result,
613+
reset: false
590614
});
591615

592616
if (afterSaveCell) {
@@ -689,12 +713,14 @@ class BootstrapTable extends Component {
689713
this.setState({
690714
data: result,
691715
selectedRowKeys: this.store.getSelectedRowKeys(),
692-
currPage
716+
currPage,
717+
reset: false
693718
});
694719
} else {
695720
result = this.store.get();
696721
this.setState({
697722
data: result,
723+
reset: false,
698724
selectedRowKeys: this.store.getSelectedRowKeys()
699725
});
700726
}
@@ -711,7 +737,8 @@ class BootstrapTable extends Component {
711737
}
712738

713739
this.setState({
714-
currPage: this.props.options.pageStartIndex || Const.PAGE_START_INDEX
740+
currPage: this.props.options.pageStartIndex || Const.PAGE_START_INDEX,
741+
reset: false
715742
});
716743

717744
if (this.isRemoteDataSource()) {
@@ -742,7 +769,8 @@ class BootstrapTable extends Component {
742769
this.store.getDataIgnoringPagination());
743770
}
744771
this.setState({
745-
data: result
772+
data: result,
773+
reset: false
746774
});
747775
}
748776

@@ -793,7 +821,8 @@ class BootstrapTable extends Component {
793821
}
794822

795823
this.setState({
796-
currPage: this.props.options.pageStartIndex || Const.PAGE_START_INDEX
824+
currPage: this.props.options.pageStartIndex || Const.PAGE_START_INDEX,
825+
reset: false
797826
});
798827

799828
if (this.isRemoteDataSource()) {
@@ -824,7 +853,8 @@ class BootstrapTable extends Component {
824853
this.store.getDataIgnoringPagination());
825854
}
826855
this.setState({
827-
data: result
856+
data: result,
857+
reset: false
828858
});
829859
}
830860

@@ -921,7 +951,8 @@ class BootstrapTable extends Component {
921951
onDropRow={ this.handleDropRow }
922952
onSearch={ this.handleSearch }
923953
onExportCSV={ this.handleExportCSV }
924-
onShowOnlySelected={ this.handleShowOnlySelected }/>
954+
onShowOnlySelected={ this.handleShowOnlySelected }
955+
reset={ this.state.reset } />
925956
</div>
926957
);
927958
} else {
@@ -1042,20 +1073,23 @@ class BootstrapTable extends Component {
10421073
result = this.store.page(firstPage, sizePerPage).get();
10431074
this.setState({
10441075
data: result,
1045-
currPage: firstPage
1076+
currPage: firstPage,
1077+
reset: false
10461078
});
10471079
} else {
10481080
const currLastPage = Math.ceil(this.store.getDataNum() / sizePerPage);
10491081
result = this.store.page(currLastPage, sizePerPage).get();
10501082
this.setState({
10511083
data: result,
1052-
currPage: currLastPage
1084+
currPage: currLastPage,
1085+
reset: false
10531086
});
10541087
}
10551088
} else {
10561089
result = this.store.get();
10571090
this.setState({
1058-
data: result
1091+
data: result,
1092+
reset: false
10591093
});
10601094
}
10611095

src/TableHeader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TableHeader extends Component {
5555
rows[0] = [ this.renderSelectRowHeader(rowCount + 1, rowKey++) ];
5656
}
5757

58-
const { sortIndicator, sortList, onSort } = this.props;
58+
const { sortIndicator, sortList, onSort, reset } = this.props;
5959

6060
React.Children.forEach(this.props.children, (elm) => {
6161
const { dataField, dataSort } = elm.props;
@@ -67,7 +67,7 @@ class TableHeader extends Component {
6767
}
6868
if ((rowSpan + rowIndex) === (rowCount + 1)) {
6969
rows[rowIndex].push(React.cloneElement(
70-
elm, { key: rowKey++, onSort, sort, sortIndicator, isOnlyHead: false }
70+
elm, { reset, key: rowKey++, onSort, sort, sortIndicator, isOnlyHead: false }
7171
));
7272
} else {
7373
rows[rowIndex].push(React.cloneElement(
@@ -140,7 +140,8 @@ TableHeader.propTypes = {
140140
isSelectAll: PropTypes.oneOf([ true, 'indeterminate', false ]),
141141
sortIndicator: PropTypes.bool,
142142
customComponent: PropTypes.func,
143-
colGroups: PropTypes.element
143+
colGroups: PropTypes.element,
144+
reset: PropTypes.bool
144145
};
145146

146147
export default TableHeader;

src/TableHeaderColumn.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ class TableHeaderColumn extends Component {
1717
this.handleFilter = this.handleFilter.bind(this);
1818
}
1919

20+
componentWillReceiveProps(nextProps) {
21+
if (nextProps.reset) {
22+
this.cleanFiltered();
23+
}
24+
}
25+
2026
handleColumnClick = () => {
2127
if (this.props.isOnlyHead || !this.props.dataSort) return;
2228
const order = this.props.sort === Const.SORT_DESC ? Const.SORT_ASC : Const.SORT_DESC;

src/store/TableDataStore.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ export class TableDataStore {
3232
this.multiColumnSort = props.multiColumnSort;
3333
}
3434

35+
clean() {
36+
this.filteredData = null;
37+
this.isOnFilter = false;
38+
this.filterObj = null;
39+
this.searchText = null;
40+
this.sortList = [];
41+
this.pageObj = {};
42+
this.selected = [];
43+
}
44+
3545
setData(data) {
3646
this.data = data;
3747
if (this.remote) {

src/toolbar/ToolBar.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ class ToolBar extends Component {
2929
);
3030
}
3131

32+
componentWillReceiveProps(nextProps) {
33+
if (nextProps.reset) {
34+
this.setSearchInput('');
35+
}
36+
}
37+
3238
componentWillUnmount() {
3339
this.clearTimeout();
3440
}
@@ -397,10 +403,12 @@ ToolBar.propTypes = {
397403
closeText: PropTypes.string,
398404
clearSearch: PropTypes.bool,
399405
ignoreEditable: PropTypes.bool,
400-
defaultSearch: PropTypes.string
406+
defaultSearch: PropTypes.string,
407+
reset: PropTypes.bool
401408
};
402409

403410
ToolBar.defaultProps = {
411+
reset: false,
404412
enableInsert: false,
405413
enableDelete: false,
406414
enableSearch: false,

0 commit comments

Comments
 (0)