a way to remove the header from a react-data-grid
Is there a way to remove the header from a react-data-grid?
good question, deserves an answer! I wish I knew, as I want to do so too. Tried <ReactDataGrid headerRowHeight={0} /> but that didn't work ...
I used the following custom style hack to hide the header.
.react-grid-Header {
display:none !important;
}
.react-grid-Viewport {
top: 0px !important;
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please reopen this if you feel it has been incorrectly closed and we will do our best to look into it. Thank you for your contributions.
in the JSX I added a wrapper:
return (
<div className = {this.showHeader ? "" : "noHeaderWrapper "} >
<ReactDataGrid />
</div>
);
and in external css I used the code from answer from @arkoblog!
.noHeaderWrapper .react-grid-Header {
display: none !important;
}
.noHeaderWrapper .react-grid-Viewport {
top: 0px !important;
}
I've found challenges with the above solution when adding rows to the react-data-gid on-the-fly. My solution was the following (based off of fierascu's solution:
<ReactDataGrid className='noHeaderWrapper' headerRowHeight={1} />
.noHeaderWrapper .react-grid-Header {
display: none;
}
As mentioned thru https://github.com/adazzle/react-data-grid/issues/834:
setting headerRowHeight=0, the height will be considered as undefined and it will use the default row height.
So setting a 1px will get the header as close to 0 as possible, and we can simply hide the header in CSS. The top position doesn't work, unfortunately, as it messes on-the-fly positional calculations of the grid. The above code will likely cause a 1px vertical offset to the grid relative to the page, but due to our repository heavily extending react-data-grid, this was favourable to row content being vertically offset to the top position.
Seriously? There's no way to have a table w/o a header?