Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant Design Table with vertical and horizontal scroll

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:

Without setting height for the table

The problem is when I set the y scroll. Bellow an example:

Setting height the table

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!

like image 604
Italo Borges Avatar asked Apr 01 '19 14:04

Italo Borges


People also ask

How do I add a vertical and horizontal scrollbar to a table?

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.

How do you make an ant design table responsive?

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.

Is horizontal scroll good?

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)

Can scroll horizontally?

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.


2 Answers

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 }}
like image 86
Afaq Ahmed Khan Avatar answered Sep 18 '22 17:09

Afaq Ahmed Khan


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:

Edit wonderful-tree-ukyy5

like image 44
Italo Borges Avatar answered Sep 19 '22 17:09

Italo Borges