React-table: Support for fixed header

Created on 4 Feb 2017  路  5Comments  路  Source: tannerlinsley/react-table

Are there any plans to support a fixed header like fixed-data-table does?

Most helpful comment

I just did this with a custom CSS (actually sass). Works great!

$headerHeight: 40px;
$rowHeight: 60px;

.ReactTable {
  position: absolute; // This is not really necesarry. I do this to span the table to the width and heigth of the parent component
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  border: none;

  .rt-table {
    height: 100%;
    display: block;

    .rt-thead {
      height: $headerHeight;
    }

    .rt-tbody { // I setup the body of the table to behave as a scroll container
      height: calc(100% - $headerHeight);
      overflow: scroll; 
      display: block;

      .rt-tr-group {
        background: white;
        height: $rowHeight;
      }
    }
  }
}

All 5 comments

I just did this with a custom CSS (actually sass). Works great!

$headerHeight: 40px;
$rowHeight: 60px;

.ReactTable {
  position: absolute; // This is not really necesarry. I do this to span the table to the width and heigth of the parent component
  left: 0px;
  top: 0px;
  width: 100%;
  height: 100%;
  border: none;

  .rt-table {
    height: 100%;
    display: block;

    .rt-thead {
      height: $headerHeight;
    }

    .rt-tbody { // I setup the body of the table to behave as a scroll container
      height: calc(100% - $headerHeight);
      overflow: scroll; 
      display: block;

      .rt-tr-group {
        background: white;
        height: $rowHeight;
      }
    }
  }
}

Look at that! Thank you thank you. My CSS skills are severely lacking these days.. I remember doing this with JavaScript years ago and it was never good.

You麓re welcome!

It麓s amazing what you can do with css today. Definetly check this flexbox guide for your secret css super weapons.

This works, but it would be really nice if you could have the table use the same scroll as the rest of the page so you can't get stuck only partially scrolled to it and then switch over to the table's separate scroll.

I tried getting this behavior with this css:

.ReactTable .rt-thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

but it didn't work.

Any suggestions for how to do this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

schaeffer11 picture schaeffer11  路  24Comments

Nizar-Rahme picture Nizar-Rahme  路  21Comments

visarts picture visarts  路  36Comments

Grsmto picture Grsmto  路  100Comments

hassankhan picture hassankhan  路  51Comments