How to make the column sticky in a wide table #5338
mohdhaider07
started this conversation in
General
Replies: 3 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.
0 replies
-
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.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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?
![Screenshot from 2024-10-12 11-25-56](https://private-user-images.githubusercontent.com/86488954/375929739-31447ff7-95a1-4344-8df5-83e5d7ebb0e0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMTEwNTQsIm5iZiI6MTczOTIxMDc1NCwicGF0aCI6Ii84NjQ4ODk1NC8zNzU5Mjk3MzktMzE0NDdmZjctOTVhMS00MzQ0LThkZjUtODNlNWQ3ZWJiMGUwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDE4MDU1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTA5OTBmZDc0NzJjMTc4MmZhYWE2YjY1YTExZjUwZjE5M2EzZmY3MTcwMWU1MmJlZDM5MDMzNjBiYmNjZTlmOWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.2olXPGhwAN8SOVOjaSbRbeGYYA9_P1Zf7rENehYGK3c)
![Screenshot from 2024-10-12 11-26-24](https://private-user-images.githubusercontent.com/86488954/375929749-3c47e3e2-d4a2-4cf5-bace-5450f56082be.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyMTEwNTQsIm5iZiI6MTczOTIxMDc1NCwicGF0aCI6Ii84NjQ4ODk1NC8zNzU5Mjk3NDktM2M0N2UzZTItZDRhMi00Y2Y1LWJhY2UtNTQ1MGY1NjA4MmJlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjEwVDE4MDU1NFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZjODMyZDlhMGUwNjgxMGYwZDAyZGIxMGM0ZDNiNTBmNWJlYzAyZTgyNTYxZGY3MWQ5YzI4YjM4MmUxOTM4MGEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.C8CIg19Z0G7nrLVX1m_uua-kiIgY6Sc1f2lOFx_fE40)
Beta Was this translation helpful? Give feedback.
All reactions