-
Notifications
You must be signed in to change notification settings - Fork 781
/
custom-caret-sort-table.js
48 lines (42 loc) · 1.11 KB
/
custom-caret-sort-table.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* eslint max-len: 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(5);
function getCaret(direction) {
if (direction === 'asc') {
return (
<span> up</span>
);
}
if (direction === 'desc') {
return (
<span> down</span>
);
}
return (
<span> up/down</span>
);
}
export default class CustomSortTable extends React.Component {
render() {
return (
<BootstrapTable data={ products }>
<TableHeaderColumn dataField='id' dataSort={ true } isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name' dataSort={ true } caretRender = { getCaret } >Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price' dataSort={ true } >Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
}