Angular Grid: Column Object
Column object represents a column in the grid. The
Column will contain a reference to the column definition your application provided as well as other column runtime information. The column contains methods and emits events.
|Returns the unique ID for the column.|
|Returns the parent column group, if column grouping is active.|
|Returns the column definition for this column. The column definition will be the result of merging the application provided column definition with any provided defaults (e.g. |
|Returns the column definition provided by the application. This may not be correct, as items can be superseded by default column options. However it's useful for comparison, eg to know which application column definition matches that column.|
|If sorting is active, returns the sort direction e.g. |
|If aggregation is set for the column, returns the aggregation function.|
|Returns the current width of the column. If the column is resized, the actual width is the new size.|
|Add event listener to the column.|
|Remove event listener from the column.|
Columns emit the following events:
|The filter active value has changed.|
|The sort value has changed.|
|The left position has changed (e.g. column has moved).|
|The width value has changed.|
|The visibility value has changed.|
|The column menu was shown / hidden.|
|The row group value has changed.|
|The pivot value has changed.|
|The 'value' value has changed.|
|The column has started / finished moving (i.e. user is dragging the column to a new location).|
All events fired by the column are synchronous (events are normally asynchronous). The grid is also listening for these events internally. This means that when you receive an event, the grid may still have some work to do (e.g. if sort has changed, the grid UI may still have to do the sorting). It is best that you do not call any grid API functions while receiving events from the column (as the grid is still processing), but instead put your logic into a timeout and call the grid in another VM tick.
When adding event listeners to a column, they will stay with the column until the column is destroyed. Columns are destroyed when you add new columns to the grid. Column objects are NOT destroyed when the columns is removed from the DOM (e.g. column virtualisation removes the column due to horizontal scrolling, or the column is made invisible via the column API).
If you add listeners to columns in custom header components, be sure to remove the listener when the header component is destroyed.
// add visibility listener to 'country' column const listener = event => console.log('Column visibility changed', event); const column = columnApi.getColumn('country'); column.addEventListener('visibleChanged', listener); // sometime later, remove the listener column.removeEventListener('visibleChanged', listener);