React-bootstrap-table2: How do I implement colspan rows?

Created on 1 Apr 2018  路  9Comments  路  Source: react-bootstrap-table/react-bootstrap-table2

colspan

How do I achieve the above feature? Like a single cell spanning across multiple columns?

Most helpful comment

Is this functionality is still not available?
It's an important feature and it should be there.

All 9 comments

@a2441918 right now we dont support this kind of feature but we must implement it.

Is this functionality is still not available?
It's an important feature and it should be there.

Any plans to implement colspan?

Team

Do we have any update on this, since this is an important feature which everyone needs this

Hello,

Has this feature been implemented yet?

As @AllenFang said, this feature doesn't supported yet, but you can do something like this using jquery:

componentDidMount() {
        $('table thead tr th').each(function (index) {
            switch (index) {
                case 0:
                    $(this).attr("colspan", 1);
                    break;
                case 1:
                    $(this).attr("colspan", 8);
                    break;
                case 2:
                    $(this).attr("colspan", 1);
                    break;
                case 3:
                    $(this).attr("colspan", 3);
                    break;
            }

        });
    }

any update on this?

We can use headerAttrs (use for header) to add colspan. But for the others, we can use attrs. Note, we have to use it in conjunction with hidden to hide the redundant cells.

export class TableWaterBalance extends Component {

  colspanForLastRow = (cell, row, rowIndex, colIndex) => {
    if (rowIndex === 1) {
      return { colSpan: `2` }
    }
  }
  hiddenColForLastRow = (cell, row, rowIndex, colIndex) => {
    if (rowIndex === 1) {
      return { hidden: true }
    }
  }
  render() {
    const columns = [{
      dataField: 'id',
      text: 'Product ID',
    }, {
      dataField: 'name',
      text: 'Product Name',
      attrs: this.colspanForLastRow
    }, {
      dataField: 'price',
      text: 'Product Price',
      attrs: this.hiddenColForLastRow
    }];
    const products = [
      { id: 'DMZ 001', name: '1234', price: '12' },
      { id: 'DMZ 002', name: '1284' }
    ]

    return (
      <div>
        <BootstrapTable keyField='id' data={products} columns={columns} />
      </div>
    )
  }
}

export default TableWaterBalance

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

prajapati-parth picture prajapati-parth  路  4Comments

rsgoss picture rsgoss  路  4Comments

ethannkschneider picture ethannkschneider  路  3Comments

bogannathan picture bogannathan  路  4Comments

kamarajuPrathi picture kamarajuPrathi  路  4Comments