question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Column Width does not work when header grouping

See original GitHub issue

Hello everyone,

Just encountered a bug, when trying to assign some width to the last TableHeaderColumn of my table.

My code:

const daysCalendarColumns = [];
    this.state.colMap.forEach(column => {
      daysCalendarColumns.push(<TableHeaderColumn columnClassName="headerDayNumCol" key={'up_' + column.colDataField} row="0" dataAlign="center">{column.colDayNumber}</TableHeaderColumn>);
      daysCalendarColumns.push(<TableHeaderColumn columnClassName={this.getDayColumnStyle(column.colDayName)} key={'dwn_' + column.colDataField} row="1" customEditor={{getElement: createLoadEditor, customEditorParameters: {dataField: column.colDataField}}} dataField={column.colDataField} dataAlign="center">{column.colDayName}</TableHeaderColumn>);
    });

    return (
      <div style={divStyle}>
        <BootstrapTable data={crasData} cellEdit={cellEditProp} hover tableStyle={{fontSize: 'x-small'}} trClassName={this.getRowClassName}>
          <TableHeaderColumn row="0" rowSpan="2" columnClassName="mainLabelCol" isKey key="mainLabel" dataField="mainLabel" width="140px" editable={false} thStyle={{borderRight: 0}}/>
          <TableHeaderColumn row="0" rowSpan="2" columnClassName="addLabelCol" key="addLabel" dataField="addLabel" width="90px" editable={false} thStyle={{borderLeft: 0}}/>

          {daysCalendarColumns}

          <TableHeaderColumn row="0" rowSpan="2" columnClassName="totalOnRowsCol" key="totalOnRow" dataField="totalLoadOnRow" width="40px" editable={false} dataAlign="right">TOTAL</TableHeaderColumn>
        </BootstrapTable>
      </div>
    );

I have some grouped headers standing for day names and nomber of the month. When I try to pu the width on the last column, i got the following error:

Uncaught TypeError: Cannot read property ‘style’ of undefined

This comes from webpack:///./~/react-bootstrap-table/lib/BootstrapTable.js @ 1431:

else { _react2.default.Children.forEach(this.props.children, function (child, i) { if (child.props.width) { header[i].style.width = child.props.width + 'px'; header[i].style.minWidth = child.props.width + 'px'; } }); }

Where it seems that this.props.children sees 65 children (yes, 2 main columns header, plus 31 days times 2 plus last TOTAL column) but there are only 35 “header” (var header = this.refs.header.getHeaderColGrouop()😉

Anyone had the same ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ThomasVuillaumecommented, Mar 28, 2017

Yes of course, no problem !

My solution was simply to put some classNames :

const theCalendarColumns = [];
    theCalendarColumns.push(<TableHeaderColumn row="0" rowSpan="2" columnClassName="mainLabelCol" isKey key="mainLabel" dataField="mainLabel" editable={false} thStyle={{borderRight: 0}}/>);
    theCalendarColumns.push(<TableHeaderColumn row="0" rowSpan="2" columnClassName="addLabelCol" key="addLabel" dataField="addLabel" editable={false} thStyle={{borderLeft: 0}}/>);
    this.state.colMap.forEach(column => {
      theCalendarColumns.push(<TableHeaderColumn columnClassName="headerDayNumCol" key={'up_' + column.colDataField} row="0" col={2 + column.colDayNumber - 1} dataAlign="center">{column.colDayNumber}</TableHeaderColumn>);
      theCalendarColumns.push(<TableHeaderColumn columnClassName={this.getDayColumnStyle(column.colDayName)} key={'dwn_' + column.colDataField} row="1" col={2 + column.colDayNumber - 1} customEditor={{getElement: createLoadEditor, customEditorParameters: {dataField: column.colDataField}}} dataField={column.colDataField} dataAlign="center" editable={editState}>{column.colDayName}</TableHeaderColumn>);
    });
    theCalendarColumns.push(<TableHeaderColumn row="0" rowSpan="2" columnClassName="totalOnRowsCol" key="totalOnRow" dataField="totalLoadOnRow" editable={false} dataAlign="right">TOTAL</TableHeaderColumn>);

(sorry for that ugly paste)

and some SCSS on top of that, especially what is important here is the combination of width+min-width as I said before:

/* Var for this file */
$total-row-col-thick: 45px;
$cell-padding: 4px;

/* >>>> SPECIAL COLUMNS STYLING */
/* Special background for columns containing weekend days */
.weDayCol{
background-color: rgb(217, 217, 217);
}

/* Main column in bold */
.mainLabelCol{
font-weight: bold;
width: 160px;
min-width: 160px;
}

/* Additional label in Italic */
.addLabelCol{
font-style: italic;
width: 150px;
}

.totalOnRowsCol{
width: $total-row-col-thick;
min-width: $total-row-col-thick;
font-weight: bold;
}
0reactions
AllenFangcommented, Jun 11, 2017

Fixed on v3.4.0, let me know if the problem still remain, thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

table-footer-group and table-header-group not taking the ...
The parent table takes the width of the Container, but the columns not taking table's width. Please find the attached image here. You...
Read more >
Column Width and Heading Grouping - Alteryx Community
The goal - In the output file - I would like column A to not be insanely wide. I always have to resize...
Read more >
Column width won't adjust - Google Groups
1. Disable auto resizing (Options... on the Table tab). · 2. Disable any exact width for the entire table. · 3. Clear any...
Read more >
column-width - CSS: Cascading Style Sheets - MDN Web Docs
The column-width CSS property sets the ideal column width in a multi-column layout. The container will have as many columns as can fit...
Read more >
Formatting text and column indicator width to the Grouping ...
1) How can I just add text to the grouping header changing it from the ... If I use this segment only on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found