From c54c54bd0a927788d2eeeb25613e82c4c77daeb2 Mon Sep 17 00:00:00 2001 From: AllenFang Date: Tue, 12 Dec 2017 20:19:34 +0800 Subject: [PATCH] add example for hide row on expanding --- examples/js/expandRow/demo.js | 5 ++ .../js/expandRow/hide-row-when-expanding.js | 87 +++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 examples/js/expandRow/hide-row-when-expanding.js diff --git a/examples/js/expandRow/demo.js b/examples/js/expandRow/demo.js index f7bdde93d..cbcb895c3 100644 --- a/examples/js/expandRow/demo.js +++ b/examples/js/expandRow/demo.js @@ -11,6 +11,7 @@ import ExpandIndicator from './expand-indicator'; import CustomExpandClassName from './custom-expand-class'; import CustomExpandIndicator from './custom-expand-indicator'; import AutoCollapse from './auto-collapse'; +import HideRowWhenExpanding from './hide-row-when-expanding'; import renderLinks from '../utils'; import { Col, Panel } from 'react-bootstrap'; @@ -65,6 +66,10 @@ class Demo extends React.Component { { renderLinks('expandRow/auto-collapse.js') } + + { renderLinks('expandRow/hide-row-when-expanding.js') } + + ); } diff --git a/examples/js/expandRow/hide-row-when-expanding.js b/examples/js/expandRow/hide-row-when-expanding.js new file mode 100644 index 000000000..c449c1736 --- /dev/null +++ b/examples/js/expandRow/hide-row-when-expanding.js @@ -0,0 +1,87 @@ +/* eslint max-len: 0 */ +import React from 'react'; +import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table'; + +const products = []; + +function addProducts(quantity) { + const startId = products.length; + for (let i = 0; i < quantity; i++) { + const id = startId + i; + if (i < 3) { + products.push({ + id: id, + name: 'Item name ' + id, + price: 2100 + i, + expand: [ { + fieldA: 'test1', + fieldB: (i + 1) * 99, + fieldC: (i + 1) * Math.random() * 100, + fieldD: '123eedd' + i + }, { + fieldA: 'test2', + fieldB: i * 99, + fieldC: i * Math.random() * 100, + fieldD: '123eedd' + i + } ] + }); + } else { + products.push({ + id: id, + name: 'Item name ' + id, + price: 2100 + i + }); + } + } +} +addProducts(5); + +class BSTable extends React.Component { + render() { + if (this.props.data) { + return ( + + Field A + Field B + Field C + Field D + ); + } else { + return (

?

); + } + } +} + +export default class HideRowWhenExpanding extends React.Component { + constructor(props) { + super(props); + } + + isExpandableRow(row) { + if (row.id < 4) return true; + else return false; + } + + expandComponent(row) { + return ( + + ); + } + + render() { + const options = { + hideRowOnExpand: true + }; + return ( + + Product ID + Product Name + Product Price + + ); + } +}