question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

style problem of Table component with fixed column and scroll attr

See original GitHub issue

Version

2.13.8

Environment

mac and pc; chrome 61;

Reproduction link

https://codepen.io/anon/pen/ooXVNx?editors=0011

Steps to reproduce

const columns = [
  {
    title: 'col1',
    dataIndex: 'col1',
    key: 'col1',
    width: 100,
  },
  ...
  {
    title: 'action',
    key: 'action',
    width: 100,
    fixed: 'right',
    render: () => <a>click</a>,
  }
]

...

<div style={{width: 500}}>
    <Table rowKey={r=>r.id} columns={columns} dataSource={data} scroll={{ x: 400 }}/>
</div>
<div style={{width: 300}}>
    <Table rowKey={r=>r.id} columns={columns} dataSource={data} scroll={{ x: 400 }}/>
</div>

What is expected?

.

What is actually happening?

当表格的父元素宽度大于表格组件设置的scroll.x的值时,设置了固定表的一列会出现重复的问题;小于或等于scroll.x时正常 image

当不确定表格的父元素的宽度时,scroll.x不好确定,这样的情况是否有一些解决方法呢?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
yesmeckcommented, Nov 13, 2017
  1. Container width should not greater than table width;
  2. Leave at least one column’s width to auto, so that table can adjust it’s width automatically.
11reactions
corkymaigrecommented, Mar 16, 2018

Antd table writes the tags (i.e., <th> and <td>) of the fixed columns two times: once with the other columns and once in a specific table tag corresponding to the fixed elements.

What you need to do is to hide the one which is with the other ones and render only the fixed one. You can do that by overwritting the CSS properties.

Use visibility: hidden instead of display: none otherwise the column next to the fixed one will go under it.

.ant-table-body .ant-table-fixed .ant-table-thead tr th:last-child,
.ant-table-body .ant-table-fixed .ant-table-tbody tr td:last-child {
  visibility: hidden;
}```

Read more comments on GitHub >

github_iconTop Results From Across the Web

Table fixed header and scrollable body - Stack Overflow
Fixed table head - CSS-only. Simply position: sticky; top: 0; your th elements. (Chrome, FF, Edge) .tableFixHead { overflow: auto; height: 100px; }...
Read more >
A table with both a sticky header and a sticky first column
It's pretty easy to make the header of a table stick to the top of the screen while scrolling through a bunch or...
Read more >
CSS - Aligned scrollable table body with fixed header
The problem. I wanted to include a component that rendered a list of entries that was scrollable whilst having a fixed header.
Read more >
How to create a table with fixed header and scrollable body
The purpose of this article is to create a table with a fixed header and scrollable body. We can create such a table...
Read more >
table-layout - CSS: Cascading Style Sheets - MDN Web Docs
This can speed up rendering time over the "automatic" layout method, but subsequent cell content might not fit in the column widths provided....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found