Core Features

Advanced Features

Angular Data GridGrid Layout

Version 36.2.0

Set the width, height and scrolling behaviour of the grid.

<!-- set width using percentages -->
<ag-grid-angular style="width: 100%; height: 100%;" />

<!-- OR set width using fixed pixels -->
<ag-grid-angular style="width: 500px; height: 200px" />

If using % for your height, then make sure the container you are putting the grid into also has height specified, as the browser will fit the div according to a percentage of the parent's height, and if the parent has no height, then this % will always be zero.

If your grid is not the size you think it should be then put a border on the grid's div and see if that's the size you want (the grid will fill this div). If it is not the size you want, then you have a CSS layout issue in your application.

DOM Layout Copy Link

There are three DOM Layout values the grid can have 'normal', 'autoHeight' and 'print'. They are used as follows:

  • normal: This is the default if nothing is specified. The grid fits the width and height of the div you provide and scrolls in both directions.
  • autoHeight: The grid's height adjusts to fit the number of rows, with optional minimum and maximum height.
  • print: No scroll bars are used and the grid renders all rows and columns. This layout is explained in Printing.

Normal Layout Copy Link

If the width and / or height change after the grid is initialised, the grid will automatically resize to fill the new area.

The example below shows setting the grid size and then changing it as the user selects the buttons.

Dynamic Resizing without Horizontal Scroll Copy Link

Sometimes you want to have columns that don't fit in the current viewport to simply be hidden altogether with no horizontal scrollbar.

To achieve this determine the width of the grid and work out how many columns could fit in that space, hiding any that don't fit, constantly updating based on the gridSizeChanged event firing, like the next example shows.

This example is best seen when opened in a new tab - then change the horizontal size of the browser and watch as columns hide/show based on the current grid size.

Dynamic Vertical Resizing Copy Link

Sometimes the grid is taller than the rows it contains. You can dynamically set the row heights to fill the available height as the following example shows:

Auto Height Layout Copy Link

Depending on your scenario, you may wish for the grid to auto-size it's height to the number of rows displayed inside the grid. This is useful if you have relatively few rows and don't want empty space between the last row and the bottom of the grid.

To allow the grid to auto-size its height to fit rows, set grid property domLayout='autoHeight'.

When domLayout='autoHeight' then your application should not set height on the grid div, as the div should be allowed flow naturally to fit the grid contents. When auto height is off then your application should set height on the grid div, as the grid will fill the div you provide it.

There is no default maximum height, which means that the grid will render all rows. When using the Server-Side Row Model, this will mean loading the entire data set. For large grids (eg >1,000 rows) the draw time of the grid will be slow, or for very large grids, your application can freeze. This is not a problem with the grid, it is a limitation on browsers on how much data they can easily display on one web page. For this reason, if showing large amounts of data, set a max height to limit the number of rows rendered.

The example below demonstrates the autoHeight feature. Notice the following:

  • As you set different numbers of rows into the grid, the grid will resize its height to just fit the rows.
  • As the grid height exceeds the height of the browser, you will need to use the browser vertical scroll to view data (or the iFrames scroll if you are looking at the example embedded below).
  • The height will also adjust as you filter, to add and remove rows.
  • If you have pinned rows, the grid will size to accommodate the pinned rows.
  • Vertical scrolling will not happen, however horizontal scrolling, including pinned columns, will work as normal.
  • You can switch the grid into and out of auto-height mode by calling api.setGridOption('domLayout', layout) or by changing the bound domLayout property.

The following example is best viewed in a new tab, so it is obvious that there are no scroll bars. When viewed inline below, the scroll bars shown are for the containing iframe, not the grid.

Minimum and Maximum Height with Auto Height Copy Link

You can constrain the height of the grid body - the scrolling rows, excluding headers and pinned rows. By default the minimum height is 150px (because a zero-height grid looks weird) and there is no maximum height. This can be customised using two theme parameters:

const myTheme = themeQuartz.withParams({
    autoHeightMinBodyHeight: 0,
    autoHeightMaxBodyHeight: 400,
});

Once the height of the available rows exceeds the maximum height, the grid stops growing and scrolls instead, using virtualisation to ensure that large datasets are rendered efficiently.

You can see the effect of minimum and maximum heights with different numbers of rows in the following example:

For details on displaying the grid in a printer friendly layout see the Print Layout page.