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

How do I implement colspan rows?

Open arunmmanoharan opened this issue 8 years ago • 9 comments

colspan

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

arunmmanoharan avatar Mar 31 '18 23:03 arunmmanoharan

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

AllenFang avatar Apr 06 '18 09:04 AllenFang

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

karan-chauhan avatar Oct 04 '18 12:10 karan-chauhan

Any plans to implement colspan?

ashcorah avatar Feb 01 '19 14:02 ashcorah

Team

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

SandeepKapalawai avatar Sep 16 '19 08:09 SandeepKapalawai

Hello,

Has this feature been implemented yet?

rhmmuh005 avatar Sep 24 '19 07:09 rhmmuh005

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;
            }

        });
    }

lraghib avatar Oct 07 '19 09:10 lraghib

any update on this?

ymihir avatar Jan 06 '20 12:01 ymihir

Use headerAttrs to add colspan and hidden.

https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/column-props.html#columnheaderattrs-object-function

https://react-bootstrap-table.github.io/react-bootstrap-table2/storybook/index.html?selectedKind=Work%20on%20Header%20Columns&selectedStory=Customize%20Column%20HTML%20attribute&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Factions%2Factions-panel

image

Avasam avatar May 30 '20 21:05 Avasam

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

phamkimtho avatar Jul 19 '20 09:07 phamkimtho