Skip to content

Instantly share code, notes, and snippets.

@AllenFang
Created November 5, 2016 05:30
Show Gist options
  • Save AllenFang/1077c175d8cdcc58e1a07b52e398d95d to your computer and use it in GitHub Desktop.
Save AllenFang/1077c175d8cdcc58e1a07b52e398d95d to your computer and use it in GitHub Desktop.
require('../../customMultiSelect.css');
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 } />
);
}
}
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>Product ID</TableHeaderColumn>
<TableHeaderColumn dataField='name'>Product Name</TableHeaderColumn>
<TableHeaderColumn dataField='price'>Product Price</TableHeaderColumn>
</BootstrapTable>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment