Angular Data GridGrid size

Set the width and height of the grid, using either absolute values or values relative to the parent container.

Set your grid's size

You need to define the grid's container as a starting point to initialize it. Usually, the div element becomes this container. This container should have defined dimensions as well as the rest of your layout. Handsontable supports relative units such as %, rem, em, vh, vw, and px.

Define the size in your CSS

Both width and height could be defined as inline styles or as a CSS class property. In this case, it's important to define what should be an overflow parent properly. Handsontable looks for the closest element with overflow: auto or overflow: hidden to use it as a scrollable container. If no such element is found, a window will be used.

TIP

Handsontable doesn't observe CSS changes for containers out of the box. If you'd like to observe it, you can define the dimensions in the configuration object or create your own observer.

Pass the size in the configuration

You can pass width and height values to Handsontable as numbers or possible CSS values for the "width"/"height" properties:

import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  height: 100,
  width: 100,
};

or

import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  height: "75%",
  width: "75%",
};

or

import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  height: "100px",
  width: "100px",
};
<hot-table [settings]="gridSettings" />

These dimensions will be set as inline styles in a container element, and overflow: hidden will be added automatically.

If container is a block element, then its parent has to have defined height. By default block element is 0px height, so 100% from 0px is still 0px.

Changes called in updateSettings() will re-render the grid with the new properties.

Troubleshooting with 100% height

When the height option is set to 100%, there are three ways to define the container’s height. Assuming you're creating an Handsontable instance that has 100% height and container is element with id #example.

const container = document.querySelector('#example');

const hot = new Handsontable(container, {
  height: '100%',
  // ...rest of config 
}
  1. Set a fixed height (in pixels) directly on the example element where Handsontable is mounted
<div class="page-wrapper">
  <!-- Other HTML element -->
  <div id="example" style="height: 500px">
    <div class="ht-root-wrapper ht-theme-main">
      <div class="ht-grid">
        <div class="ht-wrapper">
          <!-- Table content -->
        </div>
      </div>
      <!-- Table components -->
    </div>
  </div>
</div>
  1. Set a fixed height on the parent element, and then give the example itself a height of 100%
<div class="page-wrapper" style="height: 500px">
  <!-- Other HTML element -->
  <div id="example" style="height: 100%">
    <div class="ht-root-wrapper ht-theme-main">
      <div class="ht-grid">
        <div class="ht-wrapper">
          <!-- Table content -->
        </div>
      </div>
      <!-- Table components -->
    </div>
  </div>
</div>
  1. Use flexbox on the wrapper element to make the example fill the available space
<div class="page-wrapper" style="display: flex; height: 500px">
  <!-- Other HTML element -->
  <div id="example" style="flex: 1">
    <div class="ht-root-wrapper ht-theme-main">
      <div class="ht-grid">
        <div class="ht-wrapper">
          <!-- Table content -->
        </div>
      </div>
      <!-- Table components -->
    </div>
  </div>
</div>

When using Flexbox, the container automatically expands to fill the available space in the flex container. This is particularly useful when you want the grid to take up all the available space within its parent.

What if the size is not set

If you don't define any dimensions, Handsontable generates as many rows and columns as needed to fill the available space.

If your grid's contents don't fit in the viewport, the browser's native scrollbars are used for scrolling. For this to work properly, Handsontable's layout direction (e.g., layoutDirection: 'rtl') must be the same as your HTML document's layout direction (<html dir='rtl'>). Otherwise, horizontal scrolling doesn't work.

Autoresizing

Handsontable observes window resizing. If the window's dimensions have changed, then we check if Handsontable should resize itself too. Due to the performance issue, we use the debounce method to respond on window resize.

You can easily overwrite this behaviour by returning false in the beforeRefreshDimensions hook.

import { GridSettings } from "@handsontable/angular-wrapper";

gridSettings: GridSettings = {
  beforeRefreshDimensions: () => false,
};
<hot-table [settings]="gridSettings" />

Manual resizing

The Handsontable instance exposes the refreshDimensions() method, which helps you to resize grid elements properly.

TIP

To use the Handsontable API, you'll need access to the Handsontable instance. You can do that by utilizing a reference to the HotTableComponent, and reading its hotInstance property.

For more information, see the Instance access page.

hot.refreshDimensions();

You can listen for two hooks, beforeRefreshDimensions and afterRefreshDimensions.

    Related API reference