You will need to create a react component that handles the state of the pagination, and then pass one page at a time to a child component that renders the table.
var Paginate = React.createClass({
getInitialState: function() {
this.setState({
currentPage: this.props.currentPage || 0,
allRows: this.props.rows,
pageSize: this.props.pageSize || 5
});
},
getThisPage: function() {
let start = (this.state.currentPage * this.state.pageSize) - this.state.pageSize;
return this.state.allRows.slice(start, start + this.state.pageSize);
},
prevPage: function() {
let nextPage = this.state.currentPage - 1;
if (nextPage > 0) return;
this.setState(Object.assign(this.state, { currentPage: nextPage }));
},
nextPage: function() {
let nextPage = this.state.currentPage + 1;
if (nextPage > this.sate.allRows / this.state.pageSize) return;
this.setState(Object.assign(this.state, { currentPage: nextPage }));
},
render: function() {
var _this = this;
const childrenWithProps = React.Children.map(this.props.children, function(child){
return React.cloneElement(child, {
rows: _this.getThisPage()
});
});
return (<div>
{childrenWithProps}
<button onClick={this.prevPage}>previous</button>
<button onClick={this.nextPage}>next</button>
</div>);
}
});
var Table = function({ rows }) {
return (<Table
rowHeight={50}
rowsCount={rows.length}
width={5000}
height={5000}
headerHeight={50}>
<Column
header={<Cell>Col 1</Cell>}
cell={<Cell>Column 1 static content</Cell>}
width={2000}
/>
<Column
header={<Cell>Col 2</Cell>}
cell={<MyCustomCell mySpecialProp="column2" />}
width={1000}
/>
<Column
header={<Cell>Col 3</Cell>}
cell={({rowIndex, ...props}) => (
<Cell {...props}>
Data for column 3: {rows[rowIndex][2]}
</Cell>
)}
width={2000}
/>
</Table>);
});
ReactDOM.render(<Paginate rows={rows}><Table /></Paginate>,
document.getElementById('example'));