mirror of
https://github.com/gosticks/react-bootstrap-table2.git
synced 2026-06-28 21:20:04 +00:00
add stories for expand row
This commit is contained in:
138
packages/react-bootstrap-table2-example/examples/row-expand/expand-management.js
vendored
Normal file
138
packages/react-bootstrap-table2-example/examples/row-expand/expand-management.js
vendored
Normal file
@@ -0,0 +1,138 @@
|
||||
/* eslint no-unused-vars: 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 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'
|
||||
}];
|
||||
|
||||
class RowExpandManagment extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { expanded: [0, 1] };
|
||||
}
|
||||
|
||||
handleBtnClick = () => {
|
||||
if (!this.state.expanded.includes(2)) {
|
||||
this.setState(() => ({
|
||||
expanded: [...this.state.expanded, 2]
|
||||
}));
|
||||
} else {
|
||||
this.setState(() => ({
|
||||
expanded: this.state.expanded.filter(x => x !== 2)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
handleOnExpand = (row, isExpand, rowIndex, e) => {
|
||||
if (isExpand) {
|
||||
this.setState(() => ({
|
||||
expanded: [...this.state.expanded, row.id]
|
||||
}));
|
||||
} else {
|
||||
this.setState(() => ({
|
||||
expanded: this.state.expanded.filter(x => x !== row.id)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
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>
|
||||
),
|
||||
expanded: this.state.expanded,
|
||||
onExpand: this.handleOnExpand
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
<button className="btn btn-success" onClick={ this.handleBtnClick }>Expand/Collapse 3rd row</button>
|
||||
<BootstrapTable keyField="id" data={ products } columns={ columns } expandRow={ expandRow } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default class RowExpandManagment extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = { expanded: [0, 1] };
|
||||
}
|
||||
|
||||
handleBtnClick = () => {
|
||||
if (!this.state.expanded.includes(2)) {
|
||||
this.setState(() => ({
|
||||
expanded: [...this.state.expanded, 2]
|
||||
}));
|
||||
} else {
|
||||
this.setState(() => ({
|
||||
expanded: this.state.expanded.filter(x => x !== 2)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
handleOnExpand = (row, isExpand, rowIndex, e) => {
|
||||
if (isExpand) {
|
||||
this.setState(() => ({
|
||||
expanded: [...this.state.expanded, row.id]
|
||||
}));
|
||||
} else {
|
||||
this.setState(() => ({
|
||||
expanded: this.state.expanded.filter(x => x !== row.id)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
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>
|
||||
),
|
||||
expanded: this.state.expanded,
|
||||
onExpand: this.handleOnExpand
|
||||
};
|
||||
return (
|
||||
<div>
|
||||
<button className="btn btn-success" onClick={ this.handleBtnClick }>Expand/Collapse 3rd row</button>
|
||||
<BootstrapTable keyField="id" data={ products } columns={ columns } expandRow={ expandRow } />
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
72
packages/react-bootstrap-table2-example/examples/row-expand/index.js
vendored
Normal file
72
packages/react-bootstrap-table2-example/examples/row-expand/index.js
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
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>
|
||||
)
|
||||
};
|
||||
|
||||
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>
|
||||
)
|
||||
};
|
||||
|
||||
<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>
|
||||
);
|
||||
75
packages/react-bootstrap-table2-example/examples/row-expand/non-expandable-rows.js
vendored
Normal file
75
packages/react-bootstrap-table2-example/examples/row-expand/non-expandable-rows.js
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
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>
|
||||
),
|
||||
nonExpandable: [1, 3]
|
||||
};
|
||||
|
||||
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>
|
||||
),
|
||||
nonExpandable: [1, 3]
|
||||
};
|
||||
|
||||
<BootstrapTable
|
||||
keyField='id'
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
expandRow={ expandRow }
|
||||
/>
|
||||
`;
|
||||
|
||||
export default () => (
|
||||
<div>
|
||||
<h3>The second and fourth row is not expandable</h3>
|
||||
<BootstrapTable
|
||||
keyField="id"
|
||||
data={ products }
|
||||
columns={ columns }
|
||||
expandRow={ expandRow }
|
||||
/>
|
||||
<Code>{ sourceCode }</Code>
|
||||
</div>
|
||||
);
|
||||
Reference in New Issue
Block a user