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

[Feature Request] Make el-table-column width size proportional to its content #7317

Closed
alvarolemos opened this issue Sep 30, 2017 · 20 comments
Closed

Comments

@alvarolemos
Copy link

Existing Component

Yes

Component Name

el-table-column

Description

I'm working on a system that has lots of CRUD tables and I'd like their column width to be variable. Specifically, their width should fit its content. Right now, the Table-Column Attributes available doesn't support that. All the examples on the documentation uses hard-coded width, witch we rather not do in that particular project.

Is there something we are missing or this is not possible with the current API. And if it isn't, would you mind to make it possible?

Thanks in advance,

Álvaro

@alvarolemos alvarolemos changed the title [Feature Request] Make el-table-column width size to proportional to its content [Feature Request] Make el-table-column width size proportional to its content Sep 30, 2017
@hzy333
Copy link

hzy333 commented Dec 25, 2017

I have the same demand.

@ihoment-amu
Copy link

yeah , i think it 's fit of the table attributes not working by the way. or fit isn't working depend on column's content.

@vgavro
Copy link

vgavro commented Jan 24, 2018

here is related issue with material-ui, I believe problems discussed there are same.
mui/material-ui#1911

@furybean
Copy link
Contributor

furybean commented Feb 8, 2018

Sorry, we have no plan to support this.

@furybean furybean closed this as completed Feb 8, 2018
@furybean
Copy link
Contributor

furybean commented Feb 8, 2018

Sorry, we have no plan to support this.

@ghost
Copy link

ghost commented Feb 25, 2019

@alvarolemos
I needed something similar. A hacky way to do this. You have to play with numbers to get ultimate best result according to fontsize etc.

<el-table-column 
v-for="(item, index) in fields" 
min-width="50px" 
:width="item.name.length * 6 + 50 + 'px'">

@mnm1001
Copy link

mnm1001 commented Mar 9, 2020

this repository may help ex-table-column
can automatically adjust column width according to content.

Hope this can help you.

@valentinMERCIER
Copy link

valentinMERCIER commented Apr 1, 2020

No plan for re-opening this Request ?

@nicholasoxford
Copy link

Would love to have this

@astoliarov
Copy link

+1
This would be nice

@syJSdev
Copy link

syJSdev commented Sep 2, 2020

+1

@jorge-romo
Copy link

Would be nice.

1 similar comment
@BrandonMendoza
Copy link

Would be nice.

@alexanderkraemer
Copy link

alexanderkraemer commented Jan 23, 2021

Hey guys, I solved it by doing the following:
<el-table-column v-if="contentWidth" :width="contentWidth">

getContentWidth() {
   let maxWidth = 0
   this.rows.forEach(t => {
     if (t.content.length > maxWidth) {
       maxWidth = t.content.length
     }
   })
   // adding 20px width for padding
   this.contentWidth = (maxWidth + 20).toString() + 'px'
 },

I also had a watcher on the rows variable, so everytime this changed, i recalculated the width of the column.

@eloise-mcintyre
Copy link

This would be a great addition

@litoxy
Copy link

litoxy commented Sep 15, 2021

This would be a great addition

I calc the header field width and

Hey guys, I solved it by doing the following:
<el-table-column v-if="contentWidth" :width="contentWidth">

getContentWidth() {
   let maxWidth = 0
   this.rows.forEach(t => {
     if (t.content.length > maxWidth) {
       maxWidth = t.content.length
     }
   })
   // adding 20px width for padding
   this.contentWidth = (maxWidth + 20).toString() + 'px'
 },

I also had a watcher on the rows variable, so everytime this changed, i recalculated the width of the column.

I did the same. But if the content is html, it will bad - -

@Alex-wwei
Copy link

it`s so bad.

@wll8
Copy link

wll8 commented Mar 23, 2022

Similar to this parameter: https://www.antdv.com/components/table/#scroll

@jvalrog
Copy link

jvalrog commented May 27, 2022

bad framework is bad

@vildanbina
Copy link

2024 is starting and there is still no solution 😆

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