1

Both the data and the table columns I want to display are input properties in my module. Now I want to be able to give my column configuration data a flag that makes it so, that those columns are initially autosized. Finding the right columns, and executing the .autosize() function is trivial enough, but I miss a fitting event emitter on the grid itself.

(onColumnInit) seemed promising, but looking at the error text I get in my console I get the impression that one is executed before the table is even filled.

I used the official API reference, but couldn't find what I'm looking for: an event that's called when the table id done, when all data is prepared, when the table is filled, and thus ready to get resized.

If there's an alternative elegant solution I'm thankful for that too, I even played around with lifecyclehooks in my component, but as expected that's hardly a solution.

In short, I have a table control module, that functions as an internal container for the igx-grid itself, it provides our interface to the rest of the project. it gets fed with the data itself, and 'table fields', that define the field name (in the date), the shown column name, data types, and useful tags like whether the column should be sortable or not. Similarly I want to implement a tag that allows initial autosizing.

Sophor
  • 11
  • 3

1 Answers1

2

There is no elegant solution to your scenario. Currently igxGrid doesn't have a functionality to auto-size columns initially, so you have to stick to the .autosize() API. However you have to take into account the following:

  • The .autosize() API works only on the currently visible cells. By default igxGrid optimizes the DOM rendering by virtualizing it, which means that not all of the column cells are visible. Virtualization is not taking place when you set height=null for the grid, in which case all the rows are rendered and there is no vertical scrollbar. In your case you would want to go with the height=null so that the .autosize() API gives the desired outcome.
  • There is no event that the igxGrid emits when it's completely rendered - you have is to stick with the Angular lifecycle hooks. The ngAfterViewInit should work for this purpose.
Martin Pavlov
  • 462
  • 3
  • 10