diff --git a/packages/react-bootstrap-table2-example/examples/footer/column-align-table.js b/packages/react-bootstrap-table2-example/examples/footer/column-align-table.js index bb57fc6..df77d04 100644 --- a/packages/react-bootstrap-table2-example/examples/footer/column-align-table.js +++ b/packages/react-bootstrap-table2-example/examples/footer/column-align-table.js @@ -38,7 +38,8 @@ const columns = [{ footer: 'Footer 2' }, { dataField: 'price', - text: 'Product Price' + text: 'Product Price', + footer: 'Footer 3' }]; diff --git a/packages/react-bootstrap-table2-example/examples/footer/column-attrs-table.js b/packages/react-bootstrap-table2-example/examples/footer/column-attrs-table.js new file mode 100644 index 0000000..ca02cfe --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/footer/column-attrs-table.js @@ -0,0 +1,54 @@ +/* eslint no-unused-vars: 0 */ +/* eslint no-alert: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(); + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footer: 'Footer 1', + footerAttrs: { title: 'ID footer column' } +}, { + dataField: 'name', + text: 'Product Name', + footer: 'Footer 2', + footerAttrs: (column, colIndex) => ({ 'data-test': `customized data ${colIndex}` }) +}, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footer: 'Footer 1', + footerAttrs: { title: 'ID footer column' } + }, { + dataField: 'name', + text: 'Product Name', + footer: 'Footer 2', + footerAttrs: (column, colIndex) => ({ 'data-test': \`customized data \${colIndex}\` }) + }, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3' + }]; + + +`; + +export default () => ( +
+ + { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/examples/footer/column-class-table.js b/packages/react-bootstrap-table2-example/examples/footer/column-class-table.js new file mode 100644 index 0000000..60bc9e6 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/footer/column-class-table.js @@ -0,0 +1,60 @@ +/* eslint no-unused-vars: 0 */ +/* eslint no-alert: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(); + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footer: 'Footer 1' +}, { + dataField: 'name', + text: 'Product Name', + footer: 'Footer 2', + footerClasses: 'demo-row-odd' +}, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3', + footerClasses: (column, colIndex) => { + if (colIndex % 2 === 0) return 'demo-row-even'; + return 'demo-row-odd'; + } +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footer: 'Footer 1' + }, { + dataField: 'name', + text: 'Product Name', + footer: 'Footer 2', + footerClasses: 'demo-row-odd' + }, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3', + footerClasses: (column, colIndex) => { + if (colIndex % 2 === 0) return 'demo-row-even'; + return 'demo-row-odd'; + } + }]; + + +`; + +export default () => ( +
+ + { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/examples/footer/column-event-table.js b/packages/react-bootstrap-table2-example/examples/footer/column-event-table.js new file mode 100644 index 0000000..6837eee --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/footer/column-event-table.js @@ -0,0 +1,56 @@ +/* eslint no-unused-vars: 0 */ +/* eslint no-alert: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(); + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footerEvents: { + onClick: () => alert('Click on Product ID footer column') + }, + footer: 'Footer 1' +}, { + dataField: 'name', + text: 'Product Name', + footer: 'Footer 2' +}, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footerEvents: { + onClick: () => alert('Click on Product ID footer column') + }, + footer: 'Footer 1' + }, { + dataField: 'name', + text: 'Product Name', + footer: 'Footer 2' + }, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3' + }]; + + +`; + +export default () => ( +
+ + { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/examples/footer/column-style-table.js b/packages/react-bootstrap-table2-example/examples/footer/column-style-table.js new file mode 100644 index 0000000..52939f1 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/footer/column-style-table.js @@ -0,0 +1,76 @@ +/* eslint no-unused-vars: 0 */ +/* eslint no-alert: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(); + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footer: 'Footer 1' +}, { + dataField: 'name', + text: 'Product Name', + footer: 'Footer 2', + footerStyle: { + backgroundColor: '#c8e6c9' + } +}, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3', + footerStyle: (column, colIndex) => { + if (colIndex % 2 === 0) { + return { + backgroundColor: '#81c784' + }; + } + return { + backgroundColor: '#c8e6c9' + }; + } +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footer: 'Footer 1' + }, { + dataField: 'name', + text: 'Product Name', + footer: 'Footer 2', + footerStyle: { + backgroundColor: '#c8e6c9' + } + }, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3', + footerStyle: (column, colIndex) => { + if (colIndex % 2 === 0) { + return { + backgroundColor: '#81c784' + }; + } + return { + backgroundColor: '#c8e6c9' + }; + } + }]; + + +`; + +export default () => ( +
+ + { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/examples/footer/column-title-table.js b/packages/react-bootstrap-table2-example/examples/footer/column-title-table.js new file mode 100644 index 0000000..f6efed9 --- /dev/null +++ b/packages/react-bootstrap-table2-example/examples/footer/column-title-table.js @@ -0,0 +1,53 @@ +/* eslint no-unused-vars: 0 */ +import React from 'react'; + +import BootstrapTable from 'react-bootstrap-table-next'; +import Code from 'components/common/code-block'; +import { productsGenerator } from 'utils/common'; + +const products = productsGenerator(); + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footerTitle: true, + footer: 'Footer 1' +}, { + dataField: 'name', + text: 'Product Name', + footerTitle: (column, colIndex) => `this is custom title for ${column.text}`, + footer: 'Footer 2' +}, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3' +}]; + +const sourceCode = `\ +import BootstrapTable from 'react-bootstrap-table-next'; + +const columns = [{ + dataField: 'id', + text: 'Product ID', + footerTitle: true, + footer: 'Footer 1' +}, { + dataField: 'name', + text: 'Product Name', + footerTitle: (column, colIndex) => \`this is custom title for \${column.text}\`, + footer: 'Footer 2' +}, { + dataField: 'price', + text: 'Product Price', + footer: 'Footer 3' +}]; + + +`; + +export default () => ( +
+ + { sourceCode } +
+); diff --git a/packages/react-bootstrap-table2-example/stories/index.js b/packages/react-bootstrap-table2-example/stories/index.js index c2b6186..855287d 100644 --- a/packages/react-bootstrap-table2-example/stories/index.js +++ b/packages/react-bootstrap-table2-example/stories/index.js @@ -51,6 +51,11 @@ import FunctionFooter from 'examples/footer/function-footer'; import FooterClassTable from 'examples/footer/footer-class-table'; import FooterColumnFormatTable from 'examples/footer/column-format-table'; import FooterColumnAlignTable from 'examples/footer/column-align-table'; +import FooterColumnTitleTable from 'examples/footer/column-title-table.js'; +import FooterColumnEventsTable from 'examples/footer/column-event-table.js'; +import FooterColumnClassTable from 'examples/footer/column-class-table.js'; +import FooterColumnStyleTable from 'examples/footer/column-style-table.js'; +import FooterColumnAttrsTable from 'examples/footer/column-attrs-table.js'; // column filter import TextFilter from 'examples/column-filter/text-filter'; @@ -296,9 +301,14 @@ storiesOf('Footer', module) .addDecorator(bootstrapStyle()) .add('Simple Footer', () => ) .add('Function Footer', () => ) - .add('Footer Class', () => ) .add('Column Formatter', () => ) - .add('Column Align', () => ); + .add('Column Align', () => ) + .add('Column Title', () => ) + .add('Column Events', () => ) + .add('Customize Column Class', () => ) + .add('Customize Column Style', () => ) + .add('Customize Column HTML attribute', () => ) + .add('Footer Class', () => ); storiesOf('Sort Table', module) .addDecorator(bootstrapStyle()) diff --git a/packages/react-bootstrap-table2-example/stories/stylesheet/columns/_index.scss b/packages/react-bootstrap-table2-example/stories/stylesheet/columns/_index.scss index e2700ac..c91518d 100644 --- a/packages/react-bootstrap-table2-example/stories/stylesheet/columns/_index.scss +++ b/packages/react-bootstrap-table2-example/stories/stylesheet/columns/_index.scss @@ -11,10 +11,10 @@ background-color: $green-lighten-4; } -thead .header-class { +.header-class { background-color: $green-lighten-4; } -tfoot .footer-class { +.footer-class { background-color: $green-lighten-4; } \ No newline at end of file diff --git a/packages/react-bootstrap-table2/src/bootstrap-table.js b/packages/react-bootstrap-table2/src/bootstrap-table.js index c79fdc1..343fda5 100644 --- a/packages/react-bootstrap-table2/src/bootstrap-table.js +++ b/packages/react-bootstrap-table2/src/bootstrap-table.js @@ -27,7 +27,11 @@ class BootstrapTable extends PropsBaseResolver(Component) { const { loading, overlay } = this.props; if (overlay) { const LoadingOverlay = overlay(loading); - return {this.renderTable()}; + return ( + + { this.renderTable() } + + ); } return this.renderTable(); } @@ -57,25 +61,21 @@ class BootstrapTable extends PropsBaseResolver(Component) { const tableWrapperClass = cs('react-bootstrap-table', wrapperClasses); - const tableClass = cs( - 'table', - { - 'table-striped': striped, - 'table-hover': hover, - 'table-bordered': bordered, - [bootstrap4 ? 'table-sm' : 'table-condensed']: condensed - }, - classes - ); + const tableClass = cs('table', { + 'table-striped': striped, + 'table-hover': hover, + 'table-bordered': bordered, + [bootstrap4 ? 'table-sm' : 'table-condensed']: condensed + }, classes); const hasFooter = _.filter(columns, col => _.has(col, 'footer')).length > 0; - const tableCaption = caption && {caption}; + const tableCaption = (caption && { caption }); return (
- {tableCaption} + { tableCaption }