Skip to content

Instantly share code, notes, and snippets.

@AllenFang
Created October 27, 2016 15:07
Show Gist options
  • Select an option

  • Save AllenFang/ab826ffbb22b351c3261a9134be95210 to your computer and use it in GitHub Desktop.

Select an option

Save AllenFang/ab826ffbb22b351c3261a9134be95210 to your computer and use it in GitHub Desktop.
Sortable table
let order = 'desc';
class SortTable extends React.Component {
handleBtnClick = () => {
if (order === 'desc') {
this.refs.table.handleSort('asc', 'name');
order = 'asc';
} else {
this.refs.table.handleSort('desc', 'name');
order = 'desc';
}
}
render() {
return (
<div>
<p style={ { color: 'red' } }>You cam click header to sort or click following button to perform a sorting by expose API</p>
<button onClick={ this.handleBtnClick }>Sort Product Name</button>
<BootstrapTable ref='table' data={ products }>
<TableHeaderColumn dataField='id' isKey={ true } dataSort={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataSort={ true }>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment