-
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.
add example page call expose-api-table
- Loading branch information
1 parent
a49c1e2
commit 55d475f
Showing
2 changed files
with
75 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,69 @@ | ||
/* eslint max-len: 0 */ | ||
/* eslint no-console: 0 */ | ||
import React from 'react'; | ||
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table'; | ||
|
||
const products = []; | ||
|
||
function addProducts(quantity) { | ||
const startId = products.length; | ||
for (let i = 0; i < quantity; i++) { | ||
const id = startId + i; | ||
products.push({ | ||
id: id, | ||
name: 'Item name ' + id, | ||
price: 2100 + i | ||
}); | ||
} | ||
} | ||
|
||
addProducts(100); | ||
|
||
export default class ExposeApiTable extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
text: '' | ||
}; | ||
} | ||
|
||
handleClick = (rowKey) => { | ||
console.log(this.refs.table.getPageByRowKey(rowKey)); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<div className='form-inline'> | ||
{ `typing your row key -> ` } | ||
<input | ||
className='form-control' | ||
ref='rowKeyInput' | ||
onChange={ (e) => { | ||
this.setState( { | ||
text: e.target.value | ||
} ); | ||
} } | ||
value={ this.state.text } /> | ||
{ ' ' } | ||
<button | ||
className='btn btn-success' | ||
onClick={ () => { | ||
this.handleClick(parseInt(this.refs.rowKeyInput.value, 10)); | ||
} }> | ||
get the page | ||
</button> | ||
</div> | ||
<BootstrapTable | ||
ref='table' | ||
data={ products } | ||
pagination={ true } | ||
search={ true }> | ||
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn> | ||
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn> | ||
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn> | ||
</BootstrapTable> | ||
</div> | ||
); | ||
} | ||
} |