Skip to content

Commit c54c54b

Browse files
committed
add example for hide row on expanding
1 parent 07038fc commit c54c54b

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

examples/js/expandRow/demo.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import ExpandIndicator from './expand-indicator';
1111
import CustomExpandClassName from './custom-expand-class';
1212
import CustomExpandIndicator from './custom-expand-indicator';
1313
import AutoCollapse from './auto-collapse';
14+
import HideRowWhenExpanding from './hide-row-when-expanding';
1415
import renderLinks from '../utils';
1516

1617
import { Col, Panel } from 'react-bootstrap';
@@ -65,6 +66,10 @@ class Demo extends React.Component {
6566
{ renderLinks('expandRow/auto-collapse.js') }
6667
<AutoCollapse/>
6768
</Panel>
69+
<Panel header={ 'Hide Row When Expanding' }>
70+
{ renderLinks('expandRow/hide-row-when-expanding.js') }
71+
<HideRowWhenExpanding/>
72+
</Panel>
6873
</Col>
6974
);
7075
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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 HideRowWhenExpanding extends React.Component {
56+
constructor(props) {
57+
super(props);
58+
}
59+
60+
isExpandableRow(row) {
61+
if (row.id < 4) 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+
hideRowOnExpand: true
74+
};
75+
return (
76+
<BootstrapTable data={ products }
77+
options={ options }
78+
expandableRow={ this.isExpandableRow }
79+
expandComponent={ this.expandComponent }
80+
search>
81+
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
82+
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
83+
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
84+
</BootstrapTable>
85+
);
86+
}
87+
}

0 commit comments

Comments
 (0)