From 196ae3329585ebb7e4623a21657293a18435e71c Mon Sep 17 00:00:00 2001 From: AllenFang Date: Mon, 25 Mar 2019 23:07:22 +0800 Subject: [PATCH] fix #859 --- .../examples/columns/dummy-column-table.js | 301 ++++++++++-------- packages/react-bootstrap-table2/src/cell.js | 2 +- 2 files changed, 168 insertions(+), 135 deletions(-) diff --git a/packages/react-bootstrap-table2-example/examples/columns/dummy-column-table.js b/packages/react-bootstrap-table2-example/examples/columns/dummy-column-table.js index 10b6948..2e76f08 100644 --- a/packages/react-bootstrap-table2-example/examples/columns/dummy-column-table.js +++ b/packages/react-bootstrap-table2-example/examples/columns/dummy-column-table.js @@ -11,141 +11,13 @@ const products = [ { id: 14, name: 'Item 14', price: 14.5, inStock: true } ]; -const columns = [ - { - dataField: 'id', - text: 'Product ID' - }, - { - dataField: 'name', - text: 'Product Name' - }, - { - dataField: 'price', - text: 'Product Price' - }, - { - dataField: 'inStock', - text: 'In Stock', - formatter: (cellContent, row) => ( -
- -
- ) - }, - { - dataField: 'df1', - isDummyField: true, - text: 'Action 1', - formatter: (cellContent, row) => { - if (row.inStock) { - return ( -
- Available -
- ); - } - return ( -
- Backordered -
- ); - } - }, - { - dataField: 'df2', - isDummyField: true, - text: 'Action 2', - formatter: (cellContent, row) => { - if (row.inStock) { - return ( -
- Available -
- ); - } - return ( -
- Backordered -
- ); - } - } -]; - 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' - }, - { - dataField: 'inStock', - text: 'In Stock', - formatter: (cellContent, row) => ( -
- -
- ) - }, - { - dataField: 'df1', - isDummyField: true, - text: 'Action 1', - formatter: (cellContent, row) => { - if (row.inStock) { - return ( -
- Available -
- ); - } - return ( -
- Backordered -
- ); - } - }, - { - dataField: 'df2', - isDummyField: true, - text: 'Action 2', - formatter: (cellContent, row) => { - if (row.inStock) { - return ( -
- Available -
- ); - } - return ( -
- Backordered -
- ); - } - } -]; - class ProductList extends React.Component { constructor(props) { super(props); - this.state = { products }; + this.state = { products, count: 0 }; } toggleInStock = () => { @@ -163,17 +35,96 @@ class ProductList extends React.Component { }; render() { + const columns = [ + { + dataField: 'id', + text: 'Product ID', + formatter: (cell, row, rowIndex, extraData) => ( +
+ ID: {row.id} +
+ state: {extraData} +
+ ), + formatExtraData: this.state.count + }, + { + dataField: 'name', + text: 'Product Name' + }, + { + dataField: 'price', + text: 'Product Price' + }, + { + dataField: 'inStock', + text: 'In Stock', + formatter: (cellContent, row) => ( +
+ +
+ ) + }, + { + dataField: 'df1', + isDummyField: true, + text: 'Action 1', + formatter: (cellContent, row) => { + if (row.inStock) { + return ( +
+ Available +
+ ); + } + return ( +
+ Backordered +
+ ); + } + }, + { + dataField: 'df2', + isDummyField: true, + text: 'Action 2', + formatter: (cellContent, row) => { + if (row.inStock) { + return ( +
+ Available +
+ ); + } + return ( +
+ Backordered +
+ ); + } + } + ]; + return (
-

Products

+

Action 1 and Action 2 are dummy column

+ + - + { sourceCode }
); } @@ -183,7 +134,7 @@ class ProductList extends React.Component { class ProductList extends React.Component { constructor(props) { super(props); - this.state = { products }; + this.state = { products, count: 0 }; } toggleInStock = () => { @@ -200,13 +151,95 @@ class ProductList extends React.Component { this.setState(curr => ({ ...curr, products: newProducts })); }; + counter = () => { + this.setState(curr => ({ ...curr, count: this.state.count + 1 })); + } + render() { + const columns = [ + { + dataField: 'id', + text: 'Product ID', + formatter: (cell, row, rowIndex, extraData) => ( +
+ ID: {row.id} +
+ Counter: {extraData} +
+ ), + formatExtraData: this.state.count + }, + { + dataField: 'name', + text: 'Product Name' + }, + { + dataField: 'price', + text: 'Product Price' + }, + { + dataField: 'inStock', + text: 'In Stock', + formatter: (cellContent, row) => ( +
+ +
+ ) + }, + { + dataField: 'df1', + isDummyField: true, + text: 'Action 1', + formatter: (cellContent, row) => { + if (row.inStock) { + return ( +
+ Available +
+ ); + } + return ( +
+ Backordered +
+ ); + } + }, + { + dataField: 'df2', + isDummyField: true, + text: 'Action 2', + formatter: (cellContent, row) => { + if (row.inStock) { + return ( +
+ Available +
+ ); + } + return ( +
+ Backordered +
+ ); + } + } + ]; + return (

Action 1 and Action 2 are dummy column

+