MCPcopy Create free account
hub / github.com/AllenFang/react-bootstrap-table / componentWillReceiveProps

Function componentWillReceiveProps

src/BootstrapTable.js:255–361  ·  view source on GitHub ↗
(nextProps)

Source from the content-addressed store, hash-verified

253 }
254
255 componentWillReceiveProps(nextProps) {
256 this.initTable(nextProps);
257 const { options, selectRow } = nextProps;
258 let { replace } = nextProps;
259 replace = replace || this.props.replace;
260
261 if (!nextProps.data) {
262 return;
263 }
264 this.store.setData(nextProps.data.slice());
265
266 if (!replace) {
267 // from #481
268 let page = this.state.currPage;
269 if (this.props.options.page !== options.page) {
270 page = options.page;
271 }
272 // from #481
273 let sizePerPage = this.state.sizePerPage;
274 if (this.props.options.sizePerPage !== options.sizePerPage) {
275 sizePerPage = options.sizePerPage;
276 }
277
278 if (this.isRemoteDataSource()) {
279 const newState = { sizePerPage, reset: false, currPage: page };
280 let data = nextProps.data.slice();
281 if (nextProps.pagination && !this.allowRemote(Const.REMOTE_PAGE)) {
282 data = this.store.page(page, sizePerPage).get();
283 }
284
285 if (this.store.isOnFilter) {
286 if (this.store.searchText) this.handleSearch(this.store.searchText);
287 if (this.store.filterObj) this.handleFilterData(this.store.filterObj);
288 newState.currPage = Util.getFirstPage(nextProps.options.pageStartIndex);
289 } else {
290 if (!this.allowRemote(Const.REMOTE_SORT)) {
291 data = this.store.sort().get();
292 } else {
293 const { options: currentOptions } = this.props;
294 const sortName = options.sortName;
295 const sortOrder = options.sortOrder;
296 if (currentOptions.sortName !== sortName || currentOptions.sortOrder !== sortOrder) {
297 this.store.setSortInfo(sortOrder, options.sortName);
298 }
299 }
300 newState.data = data;
301 }
302 this.setState(() => newState);
303 } else {
304 // #125
305 // remove !options.page for #709
306 if (page > Math.ceil(nextProps.data.length / sizePerPage)) {
307 page = 1;
308 }
309 const sortList = this.store.getSortInfo();
310 const sortField = options.sortName;
311 const sortOrder = options.sortOrder;
312 if (sortField && sortOrder) {

Callers

nothing calls this directly

Calls 8

setDataMethod · 0.80
getMethod · 0.80
pageMethod · 0.80
setSortInfoMethod · 0.80
getSortInfoMethod · 0.80
setSelectedRowKeyMethod · 0.80
sortMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…