Skip to content

Commit 2115389

Browse files
committed
example for #1370
1 parent 53841f3 commit 2115389

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* eslint max-len: 0 */
2+
import React from 'react';
3+
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
4+
5+
const products = [];
6+
7+
function addProducts(quantity) {
8+
const startId = products.length;
9+
for (let i = 0; i < quantity; i++) {
10+
const id = startId + i;
11+
if (i < 3) {
12+
products.push({
13+
id: id,
14+
name: 'Item name ' + id,
15+
price: 2100 + i,
16+
expand: [ {
17+
fieldA: 'test1',
18+
fieldB: (i + 1) * 99,
19+
fieldC: (i + 1) * Math.random() * 100,
20+
fieldD: '123eedd' + i
21+
}, {
22+
fieldA: 'test2',
23+
fieldB: i * 99,
24+
fieldC: i * Math.random() * 100,
25+
fieldD: '123eedd' + i
26+
} ]
27+
});
28+
} else {
29+
products.push({
30+
id: id,
31+
name: 'Item name ' + id,
32+
price: 2100 + i
33+
});
34+
}
35+
}
36+
}
37+
addProducts(5);
38+
39+
class BSTable extends React.Component {
40+
render() {
41+
if (this.props.data) {
42+
return (
43+
<BootstrapTable data={ this.props.data }>
44+
<TableHeaderColumn dataField='fieldA' isKey={ true }>Field A</TableHeaderColumn>
45+
<TableHeaderColumn dataField='fieldB'>Field B</TableHeaderColumn>
46+
<TableHeaderColumn dataField='fieldC'>Field C</TableHeaderColumn>
47+
<TableHeaderColumn dataField='fieldD'>Field D</TableHeaderColumn>
48+
</BootstrapTable>);
49+
} else {
50+
return (<p>?</p>);
51+
}
52+
}
53+
}
54+
55+
export default class CustomExpandClass extends React.Component {
56+
constructor(props) {
57+
super(props);
58+
}
59+
60+
isExpandableRow(row) {
61+
if (row.id < 3) return true;
62+
else return false;
63+
}
64+
65+
expandComponent(row) {
66+
return (
67+
<BSTable data={ row.expand } />
68+
);
69+
}
70+
71+
render() {
72+
const options = {
73+
expandBodyClass: function(row, rowIndex) {
74+
if (rowIndex > 1) {
75+
return 'custom-expand-body-1';
76+
} else {
77+
return 'custom-expand-body-0';
78+
}
79+
},
80+
expandParentClass: 'custom-expand-parent' // expandParentClass also accept callback function
81+
};
82+
return (
83+
<BootstrapTable data={ products }
84+
options={ options }
85+
expandableRow={ this.isExpandableRow }
86+
expandComponent={ this.expandComponent }
87+
search>
88+
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
89+
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
90+
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
91+
</BootstrapTable>
92+
);
93+
}
94+
}

examples/js/expandRow/demo.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/* eslint max-len: 0 */
2+
require('./style.css');
23
import React from 'react';
34
import ExpandRow from './expandRow';
45
import SingleExpandRow from './single-expanding';
@@ -7,6 +8,7 @@ import ManageExpandExternal from './manage-expanding';
78
import ExpandWithSelection from './expand-row-with-selection';
89
import ExpandWithCellEdit from './expand-row-with-cellEdit';
910
import ExpandIndicator from './expand-indicator';
11+
import CustomExpandClassName from './custom-expand-class';
1012
import CustomExpandIndicator from './custom-expand-indicator';
1113
import renderLinks from '../utils';
1214

@@ -29,6 +31,10 @@ class Demo extends React.Component {
2931
{ renderLinks('expandRow/expand-indicator.js') }
3032
<ExpandIndicator/>
3133
</Panel>
34+
<Panel header={ 'Custom Expand Row ClassName' }>
35+
{ renderLinks('expandRow/custom-expand-class.js') }
36+
<CustomExpandClassName/>
37+
</Panel>
3238
<Panel header={ 'Custom Row Expand Indicator' }>
3339
{ renderLinks('expandRow/custom-expand-indicator.js') }
3440
<CustomExpandIndicator/>

examples/js/expandRow/style.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.custom-expand-parent {
2+
background-color: salmon;
3+
}
4+
5+
.custom-expand-body-1 {
6+
font-size: 8px;
7+
color: lawngreen;
8+
background-color: darkkhaki;
9+
}
10+
11+
.custom-expand-body-0 {
12+
font-size: 16px;
13+
font-weight: bold;
14+
background-color: springgreen;
15+
font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
16+
}

0 commit comments

Comments
 (0)