Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table组件的列columns添加minWidth属性,表示最小长度 #20885

Open
1 task
ctq123 opened this issue Jan 14, 2020 · 15 comments
Open
1 task

table组件的列columns添加minWidth属性,表示最小长度 #20885

ctq123 opened this issue Jan 14, 2020 · 15 comments

Comments

@ctq123
Copy link

ctq123 commented Jan 14, 2020

  • I have searched the issues of this repository and believe that this is not a duplicate.

What problem does this feature solve?

1)目前设置width属性,最终会按比例设置宽度,若屏幕宽度很小时,并且不设置scroll.x情况下,table格式就会变形;
2)其次,当每个列都设置了width,若屏幕宽度W > totalWidth(列宽度总和),即使设置了scroll.x属性,table样式也会出现变形;
3)scroll.x width 的处理方式,通常情况下scroll.x 要大于等于 totalWidth,使用过程中还要计算,调整宽度就特别不方便;
因此,特别希望增加一个minWidth属性,颗粒度由行变为列,主要是为了更好用,易用。

What does the proposed API look like?

Table列columns添加minWidth属性

@zombieJ
Copy link
Member

zombieJ commented Jan 15, 2020

Duplicate of #8981

@zombieJ zombieJ marked this as a duplicate of #8981 Jan 15, 2020
@zombieJ zombieJ closed this as completed Jan 15, 2020
@afc163
Copy link
Member

afc163 commented Jan 15, 2020

It is hard to implement it by adding css.

@harry91
Copy link

harry91 commented Apr 10, 2020

It will be really useful.

@TIS-OMiddle
Copy link

分享个目前的简单实现,1. 最后增加一列什么都没有的列,用来填充可能存在的剩余空间。 2. 倒数第二列隐藏掉右边框,让它和最后一列看起来是连在一起的。

const columns = [
  {title: 'xx', dataIndex: 'xx', width: 100},
  {title: 'xxx', dataIndex: 'xxx', width: 150},
  {title: 'xx3', dataIndex: 'xx3', width: 30, className: 'hide-right-border'}, // write a css 'hide-right-border' to hide the border
  {}, // empty column, used to adjust the table
]

@liamyoon
Copy link

liamyoon commented Mar 22, 2021

use empty column and colSpan

  const columns = [
    {
      title: 'name',
      dataIndex: 'name',
      width: 300, // min-width
      render: (text) => {
        return {
          children: (
            text // or JSX Element
          ),
          props: {
            colSpan: 2,
          },
        };
      },
    },
    {
      render: (obj) => {
        return {
          children: obj,
          props: {
            colSpan: 0,
          },
        };
      },
    }, // empty column
    {
      title: 'a column',
      dataIndex: 'modifiedDate',
      width: 120,
    },
    {
      title: 'b column',
      dataIndex: 'modifiedDate',
      width: 120,
    },
    {
      title: 'c column',
      dataIndex: 'modifiedDate',
      width: 400,
    },
    {
      title: 'd column',
      dataIndex: 'modifiedDate',
      width: 300,
    },
  ]

@noih
Copy link

noih commented May 12, 2021

use css max

  <Table.Column
    title="title"
    key="name"
    dataIndex="name"
    width="max(300px, calc(100vw - 60px))"
    ellipsis
    render={(name) => <div>{ name }</div>}
  />

@shuqianchi
Copy link

So is the problem being solved? it really useful

@antonabramovich
Copy link

antonabramovich commented May 31, 2021

@liamyoon Thanks for the direction, I've tried that solution, but unfortunately that doesn't work well with fixed header (try resizing to a less than sum of all columns widths) https://codesandbox.io/s/colspan-and-rowspan-antd4161-forked-t0ete?file=/index.js
Only seems to be borken in Chrome prior to version 91, though.

@theDoinb
Copy link

theDoinb commented Nov 5, 2021

实际项目里,特别多这种需求感觉,因为客户机器分辨率都不太一样,导致表格定宽非常麻烦,因为肯定是不希望表头换行的,但是你设置个宽度,确实不换行,但是在其他分辨率下这个列,内容不多但是占的空间很大导致留白很多,其他自动缩进的列,又可能换行了,所以说有minHeight对于表格在不同分辨率下的表现肯定是更好的

@gclb
Copy link

gclb commented Mar 18, 2022

由于ant3.x 使用了rc-table@6.x

设置clounms每个colgroup下的col中style样式变更格式如下:

columns: [{ title: '最小宽度设置', dataIndex: 'minWidth', key: 'minWidth', 'RC_TABLE_INTERNAL_COL_DEFINE': { style: { minWidth: '165px' } } }]

@btnkr
Copy link

btnkr commented May 5, 2022

It will be really useful. +1

@qwerlp
Copy link

qwerlp commented Jun 7, 2022

Duplicate of #8981

#8981的副本

咋这个属性还没加上呢,真的很有用

@qwerlp
Copy link

qwerlp commented Jun 7, 2022

2022年了,还是没有

@oskarkk
Copy link

oskarkk commented Jul 29, 2022

Thanks @liamyoon, that's the only solution that worked for me. No problems with headers or anything in Chrome or Firefox.

@fantasy1943
Copy link

@gclb 你的这个,对表格内容是有效的,但是表格标题头不生效,有办法解决吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests