I'm using Ant Design Table to show dynamic data from an internal API here in the company.
This means that I don't know what kind of data I will receive to fill each cell. It can be a large text, a number, an empty value, a short string, image, url, anything.
I need to apply horizontal and vertical scroll, but as described on Ant Design docs:
Specify the width of columns if header and cell do not align properly. (Leave one column at least without width to fit fluid layout) A fixed value which is greater than table width for scroll.x is recommended. The sum of unfixed columns should not greater than scroll.x.
Right now, the width is fine, Ant Design Table could figure out the best proportion for each column. See the image bellow:
The problem is when I set the y scroll. Bellow an example:
The major issue here is that I don't know the size of the data for each column. Speaking of columns, I have to extract the key from the table source in order to generate the columns dynamically.
Is it possible to go around this behavior?
Thanks!
Suppose we want to add a scroll bar option in HTML, use an “overflow” option and set it as auto-enabled for adding both horizontal and vertical scroll bars. If we want to add a vertical bar option in Html, add the line “overflow-y” in the files.
Just add a From To column with a custom render function, and set the responsive property on that column to only show on xs screens. The From and To columns will have the responsive property set to show on md and above.
In most cases, horizontal scroll works best when you want to display a subset of a category such as below: Displaying several images (e.g. for a photography site or a design portfolio) Displaying information in a large visual area that is not easy to see at a glance (e.g. a map)
Horizontal scrolling can be achieved by clicking and dragging a horizontal scroll bar, swiping sideways on a desktop trackpad or trackpad mouse, pressing left and right arrow keys, or swiping sideways with one's finger on a touchscreen.
So this is a known issue at Ant Design check here, here, here and here
there is not a proper fix, I faced the same issue, I tried setting the width for each column, Set "width" property in the column works, but it breaks for sticky header.
another simple way around to this is using horizontal scroll and removing vertical scroll somewhat like this
scroll={{ x: 400 }}
I came up with a workaround for my problem. In order to set a width for the entire table based on the width of my columns, I had to go through all the table data calculating each cell width based on the length of its own content.
After that, I can sum the total width and set it to the table.
Here an example using this approach:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With