0

Which one of lifecycle steps i can use to get width of column flexible table to set fixed headers like div's. For example:

var dataTable = this.refs.table;
    if (dataTable !== undefined){
        this.headers = [];
        var cells = dataTable.rows[0].cells;
        for (var i = 0; i < cells.length; i++){
            this.headers.push(
                <div style = {{width: cells[i].offsetWidth}} key = {i}>
                    {this.props.DB.activeSchema.fields[i].name}
                </div>
            );
        }

    }

....

render: function() {
 return(
 <div>
   {this.headers}
   <table class='some-fixed-table'>
      ...
   </table>
 </div>

 )

}

This is easy way of realisation, using almost pure js:

$('document').ready(function (){

  var fields = [
    'First',
    'Second',
    'Third'
  ];

  var cells = document.getElementById('table').rows[0].cells;

  for (var i = 0; i < cells.length; i++){

    var container = document.getElementById('tableHeader');
    var header = document.createElement('div');

    header.innerHTML = fields[i];
    header.style.width = cells[i].offsetWidth + 'px';  
    container.append(header);
  };
});

2 Answers 2

1

Try react-measure to get dimension of headers. I believe it will help you.

Sign up to request clarification or add additional context in comments.

Comments

1

Which one of lifecycle steps i can use to get width of column flexible table to set fixed headers like div's.

Generally use componentDidMount, but when the width is changing together with the props, use also componentWillReceiveProps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.