Skip to content

Commit 2432ab3

Browse files
committed
manage sort externally example
1 parent aec32fa commit 2432ab3

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

examples/js/sort/demo.js

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import React from 'react';
33
import SortTable from './sort-table';
44
import DefaultSortTable from './default-sort-table';
5+
import ExternalSort from './manage-sort-external-table';
56
import CustomSortTable from './custom-sort-table';
67
import CustomSortWithExtraDataTable from './custom-sort-with-extra-data-table';
78
import ReusableCustomSortTable from './reusable-custom-sort-table';
@@ -31,6 +32,15 @@ class Demo extends React.Component {
3132
</div>
3233
</div>
3334
</div>
35+
<div className='col-md-offset-1 col-md-8'>
36+
<div className='panel panel-default'>
37+
<div className='panel-heading'>Manage Sorting Externally Example</div>
38+
<div className='panel-body'>
39+
<h5>Source in /examples/js/sort/manage-sort-external-table.js</h5>
40+
<ExternalSort />
41+
</div>
42+
</div>
43+
</div>
3444
<div className='col-md-offset-1 col-md-8'>
3545
<div className='panel panel-default'>
3646
<div className='panel-heading'>Customize Table Sort Example</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* eslint max-len: 0 */
2+
/* eslint no-console: 0 */
3+
import React from 'react';
4+
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
5+
6+
7+
const products = [];
8+
9+
function addProducts(quantity) {
10+
const startId = products.length;
11+
for (let i = 0; i < quantity; i++) {
12+
const id = startId + i;
13+
products.push({
14+
id: id,
15+
name: 'Item name ' + id,
16+
price: 2100 + i
17+
});
18+
}
19+
}
20+
21+
addProducts(5);
22+
23+
export default class ExternalSort extends React.Component {
24+
constructor(props) {
25+
super(props);
26+
27+
this.state = {
28+
sortName: undefined,
29+
sortOrder: undefined
30+
};
31+
this.onSortChange = this.onSortChange.bind(this);
32+
}
33+
34+
onSortChange(sortName, sortOrder) {
35+
console.info('onSortChange', arguments);
36+
this.setState({
37+
sortName,
38+
sortOrder
39+
});
40+
}
41+
42+
render() {
43+
const options = {
44+
sortName: this.state.sortName,
45+
sortOrder: this.state.sortOrder,
46+
onSortChange: this.onSortChange
47+
};
48+
return (
49+
<div>
50+
<p style={ { color: 'red' } }>sort: sortName={ this.state.sortName }, sortOrder={ this.state.sortOrder }</p>
51+
<BootstrapTable data={ products } options={ options }>
52+
<TableHeaderColumn dataField='id' isKey={ true } dataSort={ true }>Product ID</TableHeaderColumn>
53+
<TableHeaderColumn dataField='name' dataSort={ true }>Product Name</TableHeaderColumn>
54+
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
55+
</BootstrapTable>
56+
</div>
57+
);
58+
}
59+
}

0 commit comments

Comments
 (0)