-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #233 from frontsideair/pagination2
Add example for externally managed selection state
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'use strict'; | ||
import React from 'react'; | ||
import {BootstrapTable, TableHeaderColumn} from 'react-bootstrap-table'; | ||
|
||
|
||
var products = []; | ||
|
||
function addProducts(quantity) { | ||
var startId = products.length; | ||
for (var i = 0; i < quantity; i++) { | ||
var id = startId + i; | ||
products.push({ | ||
id: id, | ||
name: "Item name " + id, | ||
price: 2100 + i | ||
}); | ||
} | ||
} | ||
|
||
addProducts(100); | ||
|
||
export default class ExternallyManagedSelection extends React.Component{ | ||
constructor(props){ | ||
super(props); | ||
this.state = { | ||
selected: [] | ||
}; | ||
} | ||
|
||
render(){ | ||
let onRowSelect = ({id}, isSelected) => { | ||
if (isSelected && this.state.selected.length !== 2) { | ||
this.setState({ selected: [...this.state.selected, id].sort() }); | ||
} | ||
else { | ||
this.setState({ selected: this.state.selected.filter(it => it !== id) }); | ||
} | ||
return false; | ||
} | ||
|
||
var selectRowProp = { | ||
mode: "checkbox", | ||
clickToSelect: true, | ||
onSelect: onRowSelect, | ||
selected: this.state.selected | ||
}; | ||
|
||
var options = { | ||
sizePerPageList: [5, 10, 15, 20], | ||
sizePerPage: 10, | ||
sortName: 'id', | ||
sortOrder: 'desc' | ||
} | ||
|
||
return ( | ||
<BootstrapTable data={products} selectRow={selectRowProp} pagination={true} options={options}> | ||
<TableHeaderColumn dataField="id" isKey={true}>Product ID</TableHeaderColumn> | ||
<TableHeaderColumn dataField="name">Product Name</TableHeaderColumn> | ||
<TableHeaderColumn dataField="price">Product Price</TableHeaderColumn> | ||
</BootstrapTable> | ||
); | ||
} | ||
}; |