Skip to content

Commit ba71655

Browse files
committed
example for #1282, able to clean sorted table manually
1 parent 261c6ea commit ba71655

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/* eslint max-len: 0 */
2+
import React from 'react';
3+
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
4+
5+
6+
const products = [];
7+
8+
function addProducts(quantity) {
9+
const startId = products.length;
10+
for (let i = 0; i < quantity; i++) {
11+
const id = startId + i;
12+
products.push({
13+
id: id,
14+
name: 'Item name ' + id,
15+
price: 2100 + i
16+
});
17+
}
18+
}
19+
20+
addProducts(5);
21+
22+
export default class CleanSortedTable extends React.Component {
23+
24+
cleanSort = () => {
25+
this.refs.table.cleanSort();
26+
}
27+
28+
render() {
29+
return (
30+
<div>
31+
<button className='btn btn-default' onClick={ this.cleanSort }>Clean Sort</button>
32+
<BootstrapTable ref='table' data={ products }>
33+
<TableHeaderColumn dataField='id' isKey dataSort>Product ID</TableHeaderColumn>
34+
<TableHeaderColumn dataField='name' dataSort>Product Name</TableHeaderColumn>
35+
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
36+
</BootstrapTable>
37+
</div>
38+
);
39+
}
40+
}

examples/js/sort/demo.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import DisableSortIndicatorTable from './disable-sort-indicator-table';
1212
import CustomCaretSortTable from './custom-caret-sort-table';
1313
import ExternalMultiSort from './manage-multi-sort-external-table';
1414
import DefaultASCSortTable from './default-asc-sort-table';
15+
import CleanSortedTable from './clean-sorted-table';
1516

1617
class Demo extends React.Component {
1718
render() {
@@ -125,6 +126,15 @@ class Demo extends React.Component {
125126
</div>
126127
</div>
127128
</div>
129+
<div className='col-md-offset-1 col-md-8'>
130+
<div className='panel panel-default'>
131+
<div className='panel-heading'>Clean Sorted Table</div>
132+
<div className='panel-body'>
133+
<h5>Source in /examples/js/sort/clean-sorted-table.js</h5>
134+
<CleanSortedTable />
135+
</div>
136+
</div>
137+
</div>
128138
</div>
129139
);
130140
}

0 commit comments

Comments
 (0)