Is there a way to capture the width of columns(header) in data table when user changes the width? I am trying to persist the changes which user makes to the columns(width) after the table is loaded. Thanks.
[SalesForce] Lighting Data table : Capture header column width when changed
Related Topic
- [SalesForce] Lightning:
with dynamic column count, want fixed width columns and scrolling instead of automatic resizing
- [SalesForce] Table as horizantal scroll and body as vertical scroll but header should be freeze
Best Answer
You can use
resize
event on datatable. You will get the parametercolumnWidths
in event.When width is changed, you can store the new widths in localStorage. You should
stringify
for storing because storage can store only strings. While loading again you can parse the array of widths and set.Below is the sample:
controller js:
NOTE:
Notice the check if stored widths are array or not. If its not array clear that item in storage and ask user to contact admin as the implementation is not correct.