How to make the column sticky in a wide table #5338
Replies: 4 comments
-
hi. without the source code, it is difficult to suggest something. always try to attach the source code or a repository with the code. |
Beta Was this translation helpful? Give feedback.
-
Here is a code for general case: <div class="wrapper">
<table>
<thead>
<tr>
<th></th>
<th>column 1</th>
<th>column 2</th>
<!-- ... -->
</tr>
</thead>
<tbody>
<tr>
<th>row 1</th>
<td>scroll</td>
<td>scroll</td>
<!-- ... -->
</tr>
<!-- ... -->
</tbody>
</table>
</div> .wrapper {
width: 320px;
height: 200px;
overflow: auto;
position: relative;
}
table {
table-layout: fixed;
}
thead,
tr>th {
position: sticky;
background: #fff;
}
thead {
top: 0;
z-index: 2;
}
tr>th {
left: 0;
z-index: 1;
}
thead tr>th:first-child {
z-index: 3;
} You may need to override default behavior of data-table, possibly by adding custom prop to table where can be passed function that will create component for your actions actions. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Can't we do it via passing some props for our shad cn table? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a table with 8-10 columns, and when performing certain actions, I often need to scroll to the right to access the "Action" column. This makes the user experience less efficient. I would like to make the "Action" column sticky, so it stays visible even when scrolling horizontally. Any suggestions or solutions on how to achieve this?


Beta Was this translation helpful? Give feedback.
All reactions