Currently, I am trying to create a table with resizable columns but have encountered a challenging issue. I want to allow the user to drag the side of a column to resize it and reset the width if needed. The problem arises when I need to reset one particular column to match the width of its content while maintaining the widths of the other columns in a table where table-layout
is set to fixed
.
When a user resets a specific column, it should revert to the width of its largest cell (similar to setting table-layout
to auto
). However, implementing this without affecting the widths of the other columns has proven to be quite challenging for me.
For instance, let's say there are two columns: A and B. Initially, with table-layout
set to auto
, column A is 200px wide, and column B is 250px wide. After allowing resizing with table-layout
set to fixed
, the user adjusts column A to 100px and column B to 150px. So, how can I enable the user to reset column B to match its content width without impacting column A or risking any changes in content?
My current solution involves temporarily switching table-layout
to auto
using JavaScript, retrieving the width of column B before saving it, reverting table-layout
back to fixed
, and then applying the saved width to column B. Although functional, I acknowledge that this approach may not be the most elegant one.
As a side note, I am utilizing the table component from ant-design in my project.