react-bootstrap-table icon indicating copy to clipboard operation
react-bootstrap-table copied to clipboard

Multiple tables with CustomMultiSelect?

Open maxkordiyak opened this issue 9 years ago • 4 comments

Hello everyone, my question is if there's a way to implement custom-multi-select-table checkboxes on let's say two tables on a page? i tried to separate the second table into other component and it didn't work. When select all is checked in the second table, it selects all items in the first one.

maxkordiyak avatar Nov 13 '17 15:11 maxkordiyak

@maxkordiyak I will check this out, thanks

AllenFang avatar Nov 15 '17 13:11 AllenFang

HI @maxkordiyak and @Gi972 . this is not a bug, in your custom input checkbox, you are suppose to use different id on input and htmlFor on label

For example: https://github.com/AllenFang/react-bootstrap-table/blob/master/examples/js/selection/custom-multi-select-table.js

if you have two table use same checkbox, you should do some changes like following:

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-1' + this.props.rowIndex } .  // << rename the id as checkbox-1
        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-1' + rowIndex }>  // << rename the id as checkbox-1
            <div className='check'></div>
          </label>
        </div>);
    } else {
      return (
        <div className='checkbox-personalized'>
          <input
            type={ type }
            name={ 'checkbox' + rowIndex }
            id={ 'checkbox-1' + rowIndex } // << rename the id as checkbox-1
            checked={ checked }
            disabled={ disabled }
            onChange={ e=> onChange(e, rowIndex) }
            ref={ input => {
              if (input) {
                input.indeterminate = props.indeterminate;
              }
            } }/>
          <label htmlFor={ 'checkbox-1' + rowIndex }> // << rename the id as checkbox-1
            <div className='check'></div>
          </label>
        </div>);
    }
  }
  render() {
    const selectRowProp = {
      mode: 'checkbox',
      test: 'second',
      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>
    );
  }
}

Anyway, dont use same id, our example is jsut a example.

AllenFang avatar Nov 19 '17 05:11 AllenFang

Ok for me. Thanks @AllenFang

Gi972 avatar Nov 20 '17 10:11 Gi972

@AllenFang : Doesn't work unfortunately!

The issue that I'm having is that if I select all rows in one table, all rows in another table get unselected.

vikramtrs avatar Aug 13 '18 18:08 vikramtrs