So I'm trying to create a React component library that has the features as its jQuery plugin counterpart
, I'm almost done with the creation of the library but the scrolling feature is one that I strangely cannot implement correctly, here's what it should look like this:
I used two different methods in order to achieve this particular effect
- I applied the following CSS properties to the
<tbody>
:
.DataTable__body {
display: block;
height: 250px; /* If the dev. chose a height of 250 pixels */
width: 100%;
overflow-y: scroll;
}
The <tbody>
has now scrolling but my <table>
has a lot of columns, it will only take up the width of the content in the first row like this:
- I set the same CSS properties to the
<table>
:
.DataTable {
/* Properties to make the scrolling effect */
display: block;
overflow-y: scroll;
width: 100%;
/* Table properties */
height: 50px;
border-collapse: collapse;
border-spacing: 0;
table-layout: fixed;
}
But it doesn't work and actually kinda broke the table:
If anyone could help me solve this issue, I would greatly appreciate it.
Also, here's the CodePen reproducing the first effect: