Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
605
Exporting igx-grid does not use column formatter correctly
posted

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.

                 

Parents
No Data
Reply
  • 700
    Offline posted

    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

Children