-
Notifications
You must be signed in to change notification settings - Fork 775
/
Copy pathcustom-multi-select-table.js
90 lines (85 loc) · 2.68 KB
/
custom-multi-select-table.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* eslint max-len: 0 */
import React from 'react';
import ReactDOM from 'react-dom';
import { BootstrapTable, TableHeaderColumn } from 'react-bootstrap-table';
require('../../customMultiSelect.css');
const products = [];
function addProducts(quantity) {
const startId = products.length;
for (let i = 0; i < quantity; i++) {
const id = startId + i;
products.push({
id: id,
name: 'Item name ' + id,
price: 2100 + i
});
}
}
addProducts(5);
class Checkbox extends React.Component {
componentDidMount() { this.update(this.props.checked); }
componentWillReceiveProps(props) { this.update(props.checked); }
update(checked) {
ReactDOM.findDOMNode(this).indeterminate = checked === 'indeterminate';
}
render() {
return (
<input className='react-bs-select-all'
type='checkbox'
name={ 'checkbox' + this.props.rowIndex }
id={ 'checkbox' + this.props.rowIndex }
checked={ this.props.checked }
onChange={ this.props.onChange } />
);
}
}
export default class CustomMultiSelectTable extends React.Component {
customMultiSelect(props) {
const { type, checked, disabled, onChange, rowIndex } = props;
/*
* If rowIndex is 'Header', means this rendering is for header selection column.
*/
if (rowIndex === 'Header') {
return (
<div className='checkbox-personalized'>
<Checkbox {...props}/>
<label htmlFor={ 'checkbox' + rowIndex }>
<div className='check'></div>
</label>
</div>);
} else {
return (
<div className='checkbox-personalized'>
<input
type={ type }
name={ 'checkbox' + rowIndex }
id={ 'checkbox' + rowIndex }
checked={ checked }
disabled={ disabled }
onChange={ e=> onChange(e, rowIndex) }
ref={ input => {
if (input) {
input.indeterminate = props.indeterminate;
}
} }/>
<label htmlFor={ 'checkbox' + rowIndex }>
<div className='check'></div>
</label>
</div>);
}
}
render() {
const selectRowProp = {
mode: 'checkbox',
customComponent: this.customMultiSelect
};
return (
<BootstrapTable data={ products } selectRow={ selectRowProp }
tableHeaderClass='custom-select-header-class' tableBodyClass='custom-select-body-class'>
<TableHeaderColumn dataField='id' isKey={ true }>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
}