ui-grid icon indicating copy to clipboard operation
ui-grid copied to clipboard

How set auto width for column ?

Open pimenovoleg opened this issue 11 years ago • 30 comments

Hi! How set auto width for column(s) ?

columnDef = [ { field: 'name', minWidth: 100, width: 'auto'}, { field: 'age', minWidth: 20, width: 'auto'} ]

pimenovoleg avatar Jul 02 '15 08:07 pimenovoleg

You can set '*' width, there is no auto width function.

PaulL1 avatar Jul 02 '15 08:07 PaulL1

May be exist equivalent "double click" on line (between columns) ? to resize a content in column.

pimenovoleg avatar Jul 02 '15 10:07 pimenovoleg

I tried '*', didnt work for me..

miah-al avatar Jul 02 '15 15:07 miah-al

And even I set width to "auto" or "*" and column have auto-size, the column brings to fixed width after any column in grid was resized manually...

fastex avatar Jul 03 '15 12:07 fastex

i believe that "*" not working, could you please help us for this point @PaulL1

tringuyenminh92 avatar Oct 04 '15 15:10 tringuyenminh92

It is working for me, based on what I want to do. What is it you are trying to do?

This set columns 1 and 3 to the size I wanted and filled the rest of the grid width with column 2

columnDefs: [
    {field: 'col1', displayName: 'Column 1', width: 175},
    {field: 'col2', displayName: 'Column 2', width: '*'},
    {field: 'col3', displayName: 'Column 3', width: 120}
],

cjp666 avatar Oct 05 '15 08:10 cjp666

It's not working to me

columnDefs: [ {field: 'col1', displayName: 'Column 1', width: 175}, {field: 'col2', displayName: 'Column 2', width: '*'}, {field: 'col3', displayName: 'Column 3', width: 120} ],

PareshSolankiMI avatar Mar 04 '16 05:03 PareshSolankiMI

It is not working for me as well.

I have tried the same: columnDefs: [ {field: 'col1', displayName: 'Column 1', width: 175}, {field: 'col2', displayName: 'Column 2', width: '*'}, {field: 'col3', displayName: 'Column 3', width: 120} ],

I have also tried: columnDefs: [ {field: 'col1', displayName: 'Column 1', width: 175}, {field: 'col2', displayName: 'Column 2', width: "*"}, {field: 'col3', displayName: 'Column 3', width: 120} ],

Eiarzate1 avatar Mar 07 '16 22:03 Eiarzate1

This doesn't seem to be working for me either. Is there a way to get the grid columns to automatically size themselves to the width of the content in the column?

joshrussell avatar Apr 29 '16 15:04 joshrussell

This is still not working for me too

ctysingh avatar Nov 25 '16 14:11 ctysingh

Hi there, this issue is still alive. So I just have a quick question: when will this fix ship in UI-Grid? Thanks in advance!

gglazer avatar Mar 01 '17 19:03 gglazer

Hi, Is there any solution for auto size column now.

balajiponraj avatar Mar 15 '17 21:03 balajiponraj

+1 Not working

prettycode avatar Mar 17 '17 17:03 prettycode

+1 Not working...pretty annoying. We'll need to put some CSS to do the trick?

Leprosy avatar Mar 17 '17 19:03 Leprosy

+1 Not working... Hello guys, any news about?

thadeuborges avatar Mar 28 '17 17:03 thadeuborges

Its a number property. Wouldn't assign string to it.

codermannn avatar Mar 29 '17 09:03 codermannn

So What? :D

nekhaly avatar Aug 18 '17 15:08 nekhaly

Hello Friends,

Actually I was trying to find a solution for this till our friends in ui-grid team find one.. I used a css class to force the cell auto size with max content.. class should be like this:


Update I found some issues with width max-content solution. I applied the same grid solution for chrome


.ui-grid-cell-contents-auto {
     /* Old Solution */
    /*min-width: max-content !important;*/
    
    /* New Solution */
    display: grid;
    grid-auto-columns: max-content;
    
    /* IE Solution */
    display: -ms-grid;
    -ms-grid-columns: max-content;
}

then you should use the property cellClass in ui-grid columns object to enable this class on your grid (something like this):

columns: [{ field: 'search_name', displayName: '', cellClass: 'ui-grid-cell-contents-auto'}]

-- I updated this to include a solution for IE browser which doesn't support max-content value for width property

nekhaly avatar Aug 18 '17 15:08 nekhaly

@nekhaly can you specify what would ui-grid-name-step will contain?

ashaik27 avatar Aug 18 '17 19:08 ashaik27

@ashaik27 sorry.. I updated it.. It should be the class name I defined above.. Thank you for the notice :)

nekhaly avatar Aug 18 '17 20:08 nekhaly