|
| 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 | +); |
0 commit comments