Handsontable editor with data loaded with AJAX

I created a HandsontableAjaxEditor that loads data with ajax.

In version 14.6.2 each time editor is opened, data is loaded and editor opens with all columns and rows displayed: https://jsfiddle.net/54g0dsv1/1/

Starting from version 15.0.0 only very small editor opens: https://jsfiddle.net/54g0dsv1/2/

In latest 18.1.2 I managed to make editor slightly larger with code added after the NOTE1, but even header row has scrollbars: https://jsfiddle.net/54g0dsv1/

Interestingly, each time a keyboard key is pressed the editor expands for one row, until all rows are displayed:

How can I make editor to take up all available size and show all data already when first opened?

Hi @marko , thanks for the report and the fiddle examples.

The editor sets its size in open(), before your AJAX data has loaded, so the inner grid gets a fixed height for an empty table. After loadData(), the grid draws only the rows that fit in that small height. getTargetDropdownHeight() then measures only those rows. That’s why the editor grows one row per keypress.

To fix it, set the inner grid back to 'auto' and render it before you measure. In your queryChoices() callback, replace the NOTE1 block with:

source.call(this.cellProperties, query, (data) => {
  this.rawData = data;
  this.updateData(this.formatData(data));

  // Let the inner grid draw every row, then measure it
  this.htEditor.updateSettings({ width: 'auto', height: 'auto' });
  this.htEditor.render();

  this.htEditor.updateSettings({
    width: this.getTargetDropdownWidth(),
    height: this.getTargetDropdownHeight(),
  });
  this.refreshDimensions();
  this.flipDropdownVerticallyIfNeeded();
  this.flipDropdownHorizontallyIfNeeded();
});

With this change on 18.1.2, the editor shows all rows with no scrollbars on the first open. It also resizes when a search returns fewer rows.

If the AJAX call can return a long list, you can cap the height by overriding getTargetDropdownHeight(), for example Math.min(super.getTargetDropdownHeight(), 300). Otherwise the editor grows to fit every row.