mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2025-10-16 11:55:39 +00:00
98 lines
2.2 KiB
JavaScript
98 lines
2.2 KiB
JavaScript
/* eslint no-console: 0 */
|
|
import React from 'react';
|
|
|
|
import BootstrapTable from 'react-bootstrap-table-next';
|
|
import Code from 'components/common/code-block';
|
|
import { productsExpandRowsGenerator } from 'utils/common';
|
|
|
|
const products = productsExpandRowsGenerator();
|
|
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID'
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name'
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
const expandRow = {
|
|
renderer: row => (
|
|
<div>
|
|
<p>{ `This Expand row is belong to rowKey ${row.id}` }</p>
|
|
<p>You can render anything here, also you can add additional data on every row object</p>
|
|
<p>expandRow.renderer callback will pass the origin row object to you</p>
|
|
</div>
|
|
),
|
|
showExpandColumn: true,
|
|
onExpand: (row, isExpand, rowIndex, e) => {
|
|
console.log(row.id);
|
|
console.log(isExpand);
|
|
console.log(rowIndex);
|
|
console.log(e);
|
|
},
|
|
onExpandAll: (isExpandAll, rows, e) => {
|
|
console.log(isExpandAll);
|
|
console.log(rows);
|
|
console.log(e);
|
|
}
|
|
};
|
|
|
|
const sourceCode = `\
|
|
import BootstrapTable from 'react-bootstrap-table-next';
|
|
|
|
const columns = [{
|
|
dataField: 'id',
|
|
text: 'Product ID'
|
|
}, {
|
|
dataField: 'name',
|
|
text: 'Product Name'
|
|
}, {
|
|
dataField: 'price',
|
|
text: 'Product Price'
|
|
}];
|
|
|
|
const expandRow = {
|
|
renderer: row => (
|
|
<div>
|
|
<p>{ \`This Expand row is belong to rowKey $\{row.id}\` }</p>
|
|
<p>You can render anything here, also you can add additional data on every row object</p>
|
|
<p>expandRow.renderer callback will pass the origin row object to you</p>
|
|
</div>
|
|
),
|
|
showExpandColumn: true,
|
|
onExpand: (row, isExpand, rowIndex, e) => {
|
|
console.log(row.id);
|
|
console.log(isExpand);
|
|
console.log(rowIndex);
|
|
console.log(e);
|
|
},
|
|
onExpandAll: (isExpandAll, rows, e) => {
|
|
console.log(isExpandAll);
|
|
console.log(rows);
|
|
console.log(e);
|
|
}
|
|
};
|
|
|
|
<BootstrapTable
|
|
keyField='id'
|
|
data={ products }
|
|
columns={ columns }
|
|
expandRow={ expandRow }
|
|
/>
|
|
`;
|
|
|
|
export default () => (
|
|
<div>
|
|
<BootstrapTable
|
|
keyField="id"
|
|
data={ products }
|
|
columns={ columns }
|
|
expandRow={ expandRow }
|
|
/>
|
|
<Code>{ sourceCode }</Code>
|
|
</div>
|
|
);
|