In order to translate lookup list database values to something that is useful to the end user, we leverage the column formatter (the display value is stored in a hidden value in the rowData).
We are trying to implement excel export, but the excel export service does not call the formatter with the correct arguments so rowData is null when we attempt to use it.
I set a breakpoint in our formatter function and riwData is undefined. I then looked at the caller and this is the js code from exportRow that is calling formatter:
let formattedValue = shouldApplyFormatter ? e.formatter(rawValue) : rawValue;
As you can see it does not include the row data in the parameter.
This is critical functionality for us because the display value in the row might not be available anywhere else.
Hello Lance,
Thank you for posting into our community!
I have been looking into your question and what I understand is that you have a column, and its display value is determined by other fields in the data source. For example:
<igx-grid #grid [data]="data"> <igx-column field="ProductID" [dataType]="'number'"> </igx-column> <igx-column field="FormattedValue" [dataType]="'string'" [formatter]="formatter"></igx-column> </igx-grid>
public data: any[] = [ { ProductID: 1, ProductName: 'Chai', UnitPrice: 18.0, }, { ProductID: 2, ProductName: 'Chang', UnitPrice: 19.0, }, { ProductID: 3, ProductName: 'Aniseed Syrup', UnitPrice: 10.0, } ]; public formatter = (value: any, rowData: any) => { return `${rowData?.ProductName} (${rowData?.UnitPrice})`; };
Could you please confirm if my impression is correct?
If it is correct, a workaround approach I could suggest is using the Excel Exporter Service’s rowExporting event and modifying the data in order for the formatted value to be exported.
Here could be found a small sample demonstrating my suggestion.
Additionally, if this is not an accurate demonstration of what you are trying to achieve, it would be highly appreciated if you could provide more detailed information about the IgxGrid configuration, the formatter function, and the underlying data source. Also, if possible, it would be great if you could provide me with a small, isolated sample that demonstrates the behavior on your side.
Having a sample that I can debug on my side will be extremely helpful in further investigating this matter and providing you with a solution as soon as possible.
Thank you for your cooperation. Looking forward to your reply.
Sincerely, Riva Ivanova Associate Software Developer
Unfortunately this suggestion will not work for us. I don't have time to create an example, but the steps to reproduce are trivial:
Add a formatter function to a column that contains the documented parameters, value and rowData, set up the formatter to access any value in rowData, it doesn't matter what it is, and export the grid. For example:
column.formatter = function (value: number, rowData: any) { return rowData.anyValue; };
You will get an undefined exception when attempting to access rowData because that parameter isn't sent by the export code to the formatter function.