can ag-grid handle display of nulls in a numerical column?
Private research annotation
Sign in to add a private research label or note.
- User
can ag-grid handle display of nulls in a numerical column?
- Assistant
Yes, ag-Grid can handle the display of nulls in a numerical column. By default, ag-Grid will display a blank cell for null values in numerical columns.
If you want to customize the way nulls are displayed in numerical columns, you can use the
valueFormatterproperty in the column definition to provide a custom formatting function. For example, you could use the following value formatter function to display the string "N/A" for null values:javascript{ headerName: 'Numeric Column', field: 'numericColumn', valueFormatter: function(params) { if (params.value === null || params.value === undefined) { return 'N/A'; } else { return params.value; } } }This code checks if the value of the cell is null or undefined, and returns the string "N/A" if it is. If the value is not null or undefined, it returns the original value.
You can also use the
valueGetterproperty in the column definition to provide a custom getter function that returns a value for nulls. For example, you could use the following value getter function to return the string "N/A" for null values:javascript{ headerName: 'Numeric Column', field: 'numericColumn', valueGetter: function(params) { if (params.data.numericColumn === null || params.data.numericColumn === undefined) { return 'N/A'; } else { return params.data.numericColumn; } } }This code checks if the
numericColumnproperty of the row data is null or undefined, and returns the string "N/A" if it is. If the value is not null or undefined, it returns the original value. - User
does aggregation still work OK if i have some nulls being displayed as N/A?
- Assistant
When you are displaying nulls as "N/A" in a numerical column, the ag-Grid aggregation will still work as expected.
By default, when ag-Grid performs an aggregation, it will ignore any null values and calculate the aggregation based on the non-null values. So if you have null values displayed as "N/A" in your grid, the aggregation will simply treat them as if they are null and exclude them from the calculation.
However, you can also configure the aggregation to include null values in the calculation by setting the
aggFuncproperty in the column definition to a custom aggregation function that handles null values as you see fit. For example, you could use the following custom aggregation function to treat "N/A" as a null value and include it in the calculation:javascript