0

I'm putting several ag-grids on one page, all with less than 15 rows, but none with the same size. So I need the grid to 'snap' to the number of rows and the column width with no scroll bars.

Setting griOptions.domLayout='autoHeight' worked perfectly for the height. Setting to 'print' is also ok.

But what do I do for width?

I can get the columns the minimum width with : this.gridColumnAPI.autoSizeAllColumns();

How to I shrink the overall grid size to insure i don't get scroll bars?

this.setWidthAndHeight('XXXpx','YYYpx') doesn't seem like an option since the height was set by domLayout.

EDIT1:

I do not specify widths in my columnDefs:

columnDefs = [
{headerName: 'Category', field: 'category' },
{headerName: 'Percent', field: 'percent' },
{headerName: 'Count', field: 'count' }  ];

EDIT2: I wrapped the ng-grid in a div with style="width:500px;height:500px" , and the grid conformed to that, so I'll be trying to dynamically set the style of that div once the gridReady event fires.

So how do I get the dimensions of the grid at any point? I know I can mine the columnApi for width of each...

mojo-jojo
  • 145
  • 1
  • 1
  • 7
  • have you tried this Ag-Grid option in your gridOptions object `onGridSizeChanged: () => this.gridOptions.api.sizeColumnsToFit()`? – Andrew Lobban Oct 04 '18 at 17:10
  • Hey Andrew- using sizeColumnsToFit expands the columns to 100% of the grid. autoSizeAllColumns() makes them the correct size, but I want the grid box itself to shrink too, width-wise. – mojo-jojo Oct 04 '18 at 17:28
  • What does your `ColDefs[]` look like? Are you specifying a width there? – Andrew Lobban Oct 04 '18 at 17:35

0 Answers0