Skip to content

Commit 056957b

Browse files
committed
add story for #1006
1 parent c12d3fa commit 056957b

File tree

3 files changed

+111
-3
lines changed

3 files changed

+111
-3
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import React from 'react';
2+
3+
import BootstrapTable from 'react-bootstrap-table-next';
4+
import Code from 'components/common/code-block';
5+
import { productsExpandRowsGenerator } from 'utils/common';
6+
7+
const products = productsExpandRowsGenerator();
8+
9+
const columns = [{
10+
dataField: 'id',
11+
text: 'Product ID'
12+
}, {
13+
dataField: 'name',
14+
text: 'Product Name'
15+
}, {
16+
dataField: 'price',
17+
text: 'Product Price'
18+
}];
19+
20+
const expandRow1 = {
21+
className: 'expanding-foo',
22+
renderer: row => (
23+
<div>
24+
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
25+
<p>You can render anything here, also you can add additional data on every row object</p>
26+
<p>expandRow.renderer callback will pass the origin row object to you</p>
27+
</div>
28+
)
29+
};
30+
31+
const expandRow2 = {
32+
className: (isExpanded, row, rowIndex) => {
33+
if (rowIndex > 2) return 'expanding-foo';
34+
return 'expanding-bar';
35+
},
36+
renderer: row => (
37+
<div>
38+
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
39+
<p>You can render anything here, also you can add additional data on every row object</p>
40+
<p>expandRow.renderer callback will pass the origin row object to you</p>
41+
</div>
42+
)
43+
};
44+
45+
46+
const sourceCode1 = `\
47+
import BootstrapTable from 'react-bootstrap-table-next';
48+
49+
const columns = // omit...
50+
51+
const expandRow = {
52+
className: 'expanding-foo',
53+
renderer: row => (
54+
<div>.....</div>
55+
)
56+
};
57+
58+
<BootstrapTable
59+
keyField='id'
60+
data={ products }
61+
columns={ columns }
62+
expandRow={ expandRow }
63+
/>
64+
`;
65+
66+
const sourceCode2 = `\
67+
import BootstrapTable from 'react-bootstrap-table-next';
68+
69+
const columns = // omit...
70+
71+
const expandRow = {
72+
className: (isExpanded, row, rowIndex) => {
73+
if (rowIndex > 2) return 'expanding-foo';
74+
return 'expanding-bar';
75+
},
76+
renderer: row => (
77+
<div>...</div>
78+
)
79+
};
80+
81+
<BootstrapTable
82+
keyField='id'
83+
data={ products }
84+
columns={ columns }
85+
expandRow={ expandRow }
86+
/>
87+
`;
88+
89+
export default () => (
90+
<div>
91+
<BootstrapTable
92+
keyField="id"
93+
data={ products }
94+
columns={ columns }
95+
expandRow={ expandRow1 }
96+
/>
97+
<Code>{ sourceCode1 }</Code>
98+
<BootstrapTable
99+
keyField="id"
100+
data={ products }
101+
columns={ columns }
102+
expandRow={ expandRow2 }
103+
/>
104+
<Code>{ sourceCode2 }</Code>
105+
</div>
106+
);

packages/react-bootstrap-table2-example/stories/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ import CustomExpandColumn from 'examples/row-expand/custom-expand-column';
167167
import ExpandColumnPosition from 'examples/row-expand/expand-column-position';
168168
import ExpandHooks from 'examples/row-expand/expand-hooks';
169169
import ParentRowClassName from 'examples/row-expand/parent-row-classname';
170+
import ExpandingRowClassName from 'examples/row-expand/expanding-row-classname';
170171

171172
// pagination
172173
import PaginationTable from 'examples/pagination';
@@ -420,7 +421,8 @@ storiesOf('Row Expand', module)
420421
.add('Custom Expand Indicator', () => <CustomExpandColumn />)
421422
.add('Expand Column Position', () => <ExpandColumnPosition />)
422423
.add('Expand Hooks', () => <ExpandHooks />)
423-
.add('Custom Parent Row ClassName', () => <ParentRowClassName />);
424+
.add('Custom Parent Row ClassName', () => <ParentRowClassName />)
425+
.add('Custom Expanding Row ClassName', () => <ExpandingRowClassName />);
424426

425427
storiesOf('Pagination', module)
426428
.addDecorator(bootstrapStyle())
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
.parent-expand-foo {
1+
.expanding-foo, .parent-expand-foo {
22
background-color: coral;
33
}
44

5-
.parent-expand-bar {
5+
.expanding-bar, .parent-expand-bar {
66
background-color: aqua;
77
}

0 commit comments

Comments
 (0)