From 3608056b004af57e7e90801c53f4f1266fa10bfb Mon Sep 17 00:00:00 2001 From: AllenFang Date: Sat, 21 Jan 2017 14:58:49 +0800 Subject: [PATCH] add example for expandrow with cell editing --- examples/js/expandRow/demo.js | 5 ++ .../js/expandRow/expand-row-with-cellEdit.js | 90 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 examples/js/expandRow/expand-row-with-cellEdit.js diff --git a/examples/js/expandRow/demo.js b/examples/js/expandRow/demo.js index b9f2626b4..331acc83b 100644 --- a/examples/js/expandRow/demo.js +++ b/examples/js/expandRow/demo.js @@ -4,6 +4,7 @@ import ExpandRow from './expandRow'; import ExpandByColumn from './expand-row-by-column'; import ManageExpandExternal from './manage-expanding'; import ExpandWithSelection from './expand-row-with-selection'; +import ExpandWithCellEdit from './expand-row-with-cellEdit'; import renderLinks from '../utils'; import { Col, Panel } from 'react-bootstrap'; @@ -33,6 +34,10 @@ class Demo extends React.Component { { renderLinks('expandRow/expand-row-with-selection.js') } + + { renderLinks('expandRow/expand-row-with-cellEdit.js') } + + ); } diff --git a/examples/js/expandRow/expand-row-with-cellEdit.js b/examples/js/expandRow/expand-row-with-cellEdit.js new file mode 100644 index 000000000..6e3978d8b --- /dev/null +++ b/examples/js/expandRow/expand-row-with-cellEdit.js @@ -0,0 +1,90 @@ +/* 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 ExpandRow extends React.Component { + constructor(props) { + super(props); + } + + isExpandableRow(row) { + if (row.id < 3) return true; + else return false; + } + + expandComponent(row) { + return ( + + ); + } + + render() { + const options = { + expandRowBgColor: 'rgb(242, 255, 163)' + }; + const cellEdit = { + mode: 'click' + }; + return ( + + Product ID + Product Name + Product Price + + ); + } +}