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

'auto' column widths do not work

Open wattsbn opened this issue 13 years ago • 39 comments

Unless I am missing something, setting a column width to 'auto' does not work any longer. Based on the documentation I found for this feature (https://github.com/angular-ui/ng-grid/wiki/Defining-columns), I assumed it would size the column to the size of its cells' contents. However, it seems to be always be set to the same really small width.

Here is a simple example of what I am seeing: http://plnkr.co/edit/1l2dwY?p=preview

wattsbn avatar Jul 16 '13 14:07 wattsbn

why set any width? (ie. let it auto-size it for you from available space). Or are you purposely trying to set the width to the largest cell value? In my tables I used fixed widths for columns that are known sizes (like quantity, price, icon columns etc.) and then use either % or do not define a width for the rest and let the size appropriately. So far I have been happy with their layout (plus a user can resize if needed)

jadrake75 avatar Jul 17 '13 06:07 jadrake75

I'm sure I could figure out a different way to accomplish what I am looking for and in the meantime that is what I will have to do. However, I still think the 'auto' width feature is currently broken and would nice just to be able to use that. Otherwise, (if it isn't broken) I would like to know how to properly use the 'auto' width feature.

wattsbn avatar Jul 17 '13 11:07 wattsbn

Is there any estimate on when this issue will be addressed?

slav avatar Aug 23 '13 18:08 slav

I'm looking at this right now.

roblarsen avatar Aug 26 '13 18:08 roblarsen

So... I know what the problem is.

On initial load, this can't do anything because... it's called too early. This plunk illustrates it, there's a debugger set right after the call to $utils.getElementsByClassName so it's stopping execution right after the call. You don't need to look for very long to see that there aren't going to be any "col1" classed elements to measure against.

Now to fix it.

roblarsen avatar Aug 27 '13 22:08 roblarsen

@roblarsen - any word on whether this is getting fixed?

slav avatar Sep 13 '13 14:09 slav

The real question is not whether, but when I'm busy this week, but will be able to look at this and a few other issues next week some time.

roblarsen avatar Sep 13 '13 14:09 roblarsen

Great, thank you. Highly appreciate it.

slav avatar Sep 13 '13 14:09 slav

I am waiting for this issue to resolve. I have column for messages of varying sizes so need to adjust the width based on widest message in all rows.

KapilRakh avatar Sep 27 '13 17:09 KapilRakh

Any word on the progress on this? Thank you!

slav avatar Oct 13 '13 00:10 slav

I am also working on a project that needs this.

mshuffett avatar Oct 18 '13 16:10 mshuffett

Just going to also say this seems like a useful functionality to have! thanks for looking into fixing it!

lucas avatar Nov 02 '13 23:11 lucas

any news about this issue ? is there a temp solution until this issue fixed ?

dshmaya avatar Jan 02 '14 16:01 dshmaya

Just wondering if this is still being worked on or was it put in the too hard basket?

aaron25 avatar Jan 14 '14 05:01 aaron25

Not too hard. Just not being worked on at present.

roblarsen avatar Jan 14 '14 05:01 roblarsen

Is there an ETA? Just wondering if I should starting looking for an alternative?

aaron25 avatar Jan 14 '14 05:01 aaron25

Hi I have a UI that is switching back and forth from grid view to treemap view. once I change the model in the treemap view and switch back to grid - all columns were shrink-ed until the columns get the update. This is very bad UX.... will appreciate a solution. Thanks Charlie.

charliehavak avatar Jan 27 '14 13:01 charliehavak

a workaround would also be appreciated.

charliehavak avatar Jan 27 '14 13:01 charliehavak

workaround : you can add to the gridOptions init function like this : $scope.gridOptions = { ... init: function (gridCtrl, gridScope) { gridScope.$on('ngGridEventData', function () { $timeout(function (){ angular.forEach(gridScope.columns, function (col) { gridCtrl.resizeOnData(col); }); }); }); } }

dshmaya avatar Feb 04 '14 11:02 dshmaya

thanks you still did not work for me...:)

charliehavak avatar Feb 06 '14 13:02 charliehavak