Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to auto size column width in AngularJS ui-grid

In AngularJS ui-grid , how can I configure the grid so that it can auto adjust the width of the columns according to the contents when it render?

I know there is a tutorial showing the auto size function, but that works only when you double click the column, I wish it could happen when the grid is initiated.

like image 905
Tony Avatar asked May 21 '15 20:05

Tony


2 Answers

use an asterisk in your column definition:

width:"*";
like image 111
cramroop Avatar answered Oct 05 '22 10:10

cramroop


There is a pluggin that do this: ui-grid-auto-fit-columns

GitHub: https://github.com/Den-dp/ui-grid-auto-fit-columns

Example: http://jsbin.com/tufazaw/edit?js,output

Usage:

<div ui-grid="gridOptions" ui-grid-auto-fit-columns></div>

angular.module('app', ['ui.grid', 'ui.grid.autoFitColumns'])
like image 28
Leonel Thiesen Avatar answered Oct 05 '22 10:10

Leonel Thiesen