diff --git a/src/BootstrapTable.js b/src/BootstrapTable.js index 99efb75ed..9db196b0c 100644 --- a/src/BootstrapTable.js +++ b/src/BootstrapTable.js @@ -21,19 +21,8 @@ class BootstrapTable extends Component { if (Util.canUseDOM()) { this.isIE = document.documentMode; } - if (!Array.isArray(this.props.data)) { - this.store = new TableDataStore(this.props.data.getData()); - this.props.data.clear(); - this.props.data.on('change', (data) => { - this.store.setData(data); - this.setState({ - data: this.getTableData() - }); - }); - } else { - const copy = this.props.data.slice(); - this.store = new TableDataStore(copy); - } + + this.store = new TableDataStore(this.props.data.slice()); this.initTable(this.props); @@ -145,27 +134,27 @@ class BootstrapTable extends Component { componentWillReceiveProps(nextProps) { this.initTable(nextProps); const { options, selectRow } = nextProps; - if (Array.isArray(nextProps.data)) { - this.store.setData(nextProps.data.slice()); - let page = options.page || this.state.currPage; - const sizePerPage = options.sizePerPage || this.state.sizePerPage; - - // #125 - if (!options.page && - page >= Math.ceil(nextProps.data.length / sizePerPage)) { - page = 1; - } - const sortInfo = this.store.getSortInfo(); - const sortField = options.sortName || (sortInfo ? sortInfo.sortField : undefined); - const sortOrder = options.sortOrder || (sortInfo ? sortInfo.order : undefined); - if (sortField && sortOrder) this.store.sort(sortOrder, sortField); - const data = this.store.page(page, sizePerPage).get(); - this.setState({ - data, - currPage: page, - sizePerPage - }); + + this.store.setData(nextProps.data.slice()); + let page = options.page || this.state.currPage; + const sizePerPage = options.sizePerPage || this.state.sizePerPage; + + // #125 + if (!options.page && + page >= Math.ceil(nextProps.data.length / sizePerPage)) { + page = 1; } + const sortInfo = this.store.getSortInfo(); + const sortField = options.sortName || (sortInfo ? sortInfo.sortField : undefined); + const sortOrder = options.sortOrder || (sortInfo ? sortInfo.order : undefined); + if (sortField && sortOrder) this.store.sort(sortOrder, sortField); + const data = this.store.page(page, sizePerPage).get(); + this.setState({ + data, + currPage: page, + sizePerPage + }); + if (selectRow && selectRow.selected) { // set default select rows to store. const copy = selectRow.selected.slice(); diff --git a/src/index.js b/src/index.js index c21c0d646..aa3c74052 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,11 @@ import BootstrapTable from './BootstrapTable'; import TableHeaderColumn from './TableHeaderColumn'; -import { TableDataSet } from './store/TableDataStore'; if (typeof window !== 'undefined') { window.BootstrapTable = BootstrapTable; window.TableHeaderColumn = TableHeaderColumn; - window.TableDataSet = TableDataSet; } export { BootstrapTable, - TableHeaderColumn, - TableDataSet + TableHeaderColumn }; diff --git a/src/store/TableDataStore.js b/src/store/TableDataStore.js index 065c88193..a4babd61b 100644 --- a/src/store/TableDataStore.js +++ b/src/store/TableDataStore.js @@ -3,7 +3,6 @@ /* eslint no-console: 0 */ /* eslint eqeqeq: 0 */ import Const from '../Const'; -const EventEmitter = require('events').EventEmitter; function _sort(arr, sortField, order, sortFunc) { order = order.toLowerCase(); @@ -22,25 +21,6 @@ function _sort(arr, sortField, order, sortFunc) { return arr; } -export class TableDataSet extends EventEmitter { - constructor(data) { - super(data); - this.data = data; - } - - setData(data) { - this.emit('change', data); - } - - clear() { - this.data = null; - } - - getData() { - return this.data; - } -} - export class TableDataStore { constructor(data) {