File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import UnSelectableTable from './unselectable-table';
66import ClickToSelectTable from './click-to-select-table' ;
77import DefaultSelectTable from './default-select-table' ;
88import SelectBgColorTable from './select-bgcolor-table' ;
9+ import SelectBgColorDynamicTable from './select-bgcolor-dynamic-table' ;
910import SelectHookTable from './select-hook-table' ;
1011import HideSelectionColumnTable from './hide-selection-col-table' ;
1112import SelectValidationTable from './select-validation-table' ;
@@ -83,6 +84,15 @@ class Demo extends React.Component {
8384 </ div >
8485 </ div >
8586 </ div >
87+ < div className = 'col-md-offset-1 col-md-8' >
88+ < div className = 'panel panel-default' >
89+ < div className = 'panel-heading' > Selected Row Bgcolor Depends on Data Example</ div >
90+ < div className = 'panel-body' >
91+ < h5 > Source in /examples/js/selection/select-bgcolor-dynamic-table.js</ h5 >
92+ < SelectBgColorDynamicTable />
93+ </ div >
94+ </ div >
95+ </ div >
8696 < div className = 'col-md-offset-1 col-md-8' >
8797 < div className = 'panel panel-default' >
8898 < div className = 'panel-heading' > Selection Hook Example</ div >
Original file line number Diff line number Diff line change 1+ /* eslint max-len: 0 */
2+ import React from 'react' ;
3+ import { BootstrapTable , TableHeaderColumn } from 'react-bootstrap-table' ;
4+
5+
6+ const products = [ ] ;
7+
8+ function addProducts ( quantity ) {
9+ const startId = products . length ;
10+ for ( let i = 0 ; i < quantity ; i ++ ) {
11+ const id = startId + i ;
12+ products . push ( {
13+ id : id ,
14+ name : 'Item name ' + id ,
15+ price : 2100 + i
16+ } ) ;
17+ }
18+ }
19+
20+ addProducts ( 5 ) ;
21+
22+ const selectRowProp = {
23+ mode : 'checkbox' ,
24+ bgColor : function ( row , isSelect ) {
25+ if ( isSelect ) {
26+ const { id } = row ;
27+ if ( id < 2 ) return 'blue' ;
28+ else if ( id < 4 ) return 'red' ;
29+ else return 'yellow' ;
30+ }
31+ return null ;
32+ }
33+ } ;
34+
35+ export default class SelectBgColorDynamicTable extends React . Component {
36+ render ( ) {
37+ return (
38+ < BootstrapTable data = { products } selectRow = { selectRowProp } >
39+ < TableHeaderColumn dataField = 'id' isKey = { true } > Product ID</ TableHeaderColumn >
40+ < TableHeaderColumn dataField = 'name' > Product Name</ TableHeaderColumn >
41+ < TableHeaderColumn dataField = 'price' > Product Price</ TableHeaderColumn >
42+ </ BootstrapTable >
43+ ) ;
44+ }
45+ }
You can’t perform that action at this time.
0 commit comments