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
135
IgxExcelExporterOptions cutting off everything after the first comma
posted

I am configuring my pivot grid like so:

 
  private configurePivotGrid() {
    const formatter = (value) => {
      // Check if the value is a valid number
      if (isNaN(value) || value === null || value === undefined) {
        return '';
      }
      
      // Format the value to two decimal places
      return new Intl.NumberFormat('en-US', {
        minimumFractionDigits: 2,
        maximumFractionDigits: 2,
      }).format(value);
    };

    const areaTypeDimensions = this.areaTypeList.map(areaType => ({
      memberName: areaType.name,
      displayName: areaType.name,
      memberFunction: (record) => {
        const areaTypeValue = record.areaTypeValues.find(value => value.areaType === areaType.name);
        return areaTypeValue ? `${areaTypeValue.areaValue}` : '';
      },
      enabled: false
    }));

    this.pivotConfig = {
      pivotKeys: {
        aggregations: 'aggregations',
        records: 'records',
        children: 'children',
        level: 'level',
        columnDimensionSeparator: '*',
        rowDimensionSeparator: '*',
      },
      columns: [

      ],
      rows: [
        { memberName: 'discipline', displayName: 'Discipline', enabled: false},
        { memberName: 'schedule', displayName: 'Schedule', enabled: false}
      ],
      values: [
        {
          member: 'quantity',
          displayName: 'Quantity',
          aggregate: {
            aggregator: IgxPivotNumericAggregate.sum,
            key: 'SUM',
            label: 'SUM'
          },
          enabled: true,
          formatter: (value) => formatter(value)
        },
        {
          member: 'labourCost',
          displayName: 'Labour Cost',
          aggregate: {
            aggregator: IgxPivotNumericAggregate.sum,
            key: 'SUM',
            label: 'SUM'
          },
          enabled: true,
          formatter: (value) => formatter(value)
        },
        {
          member: 'materialCost',
          displayName: 'Material Cost',
          aggregate: {
            aggregator: IgxPivotNumericAggregate.sum,
            key: 'SUM',
            label: 'SUM'
          },
          enabled: true,
          formatter: (value) => formatter(value)
        },
        {
          member: 'totalCost',
          displayName: 'Total Cost',
          aggregate: {
            aggregator: IgxPivotNumericAggregate.sum,
            key: 'SUM',
            label: 'SUM'
          },
          enabled: true,
          formatter: (value) => formatter(value)
        },
        {
          member: 'manhours',
          displayName: 'Manhours',
          aggregate: {
            aggregator: IgxPivotNumericAggregate.sum,
            key: 'SUM',
            label: 'SUM'
          },
          enabled: true,
          formatter: (value) => formatter(value)
        },
        {
          member: 'factoredManhours',
          displayName: 'Factored Manhours',
          aggregate: {
            aggregator: IgxPivotNumericAggregate.sum,
            key: 'SUM',
            label: 'SUM'
          },
          enabled: true,
          formatter: (value) => formatter(value)
        },
        {
          member: 'ccr',
          displayName: 'CCR',
          aggregate: {
            aggregator: IgxPivotNumericAggregate.sum,
            key: 'SUM',
            label: 'SUM'
          },
          enabled: true,
          formatter: (value) => formatter(value)
        }
      ],

      filters: [
        {
          memberName: 'drawingNumber',
          displayName: 'Drawing Number',
          enabled: false,
        },
        ...areaTypeDimensions,
        { memberName: 'drawingSheet', displayName: 'Drawing Sheet', enabled: false},
        { memberName: 'drawingRevision', displayName: 'Drawing Revision', enabled: false},
        { memberName: 'r6Item', displayName: 'R6 Item', enabled: false},
        { memberName: 'r7Item', displayName: 'R7 Item', enabled: false},
        { memberName: 'material', displayName: 'Material', enabled: false},
        { memberName: 'unitSymbol', displayName: 'Unit Symbol', enabled: false}
      ]
    };
  }

  public exportButtonHandler() {
    this.excelExportService.export(this.boqPivotGrid, new IgxExcelExporterOptions('BOQ Pivot Data'));
  }

<button *ngIf="boqGridRows && boqGridRows.length > 0 && hasDownloadPermissions" igxButton="contained" (click)="exportButtonHandler()" class="export-button">Export To Excel</button>

<div class="pivot-container" [hidden]="!(boqGridRows && boqGridRows.length > 0)">
    <igx-pivot-grid #boqPivotGrid [data]="boqGridRows" [pivotConfiguration]="pivotConfig" height="100%"  width="100%" [superCompactMode]="true" [defaultExpandState]='true' >

    </igx-pivot-grid>

    <igx-pivot-data-selector [grid]="boqPivotGrid"></igx-pivot-data-selector>
</div>



the reason for formatting the values like so:

          formatter: (value) => formatter(value)


was so that the tooltip would should the values to 2 decimal places but we still have our comma separated values. The issue I'm having now is that when I export to excel using the method exportButtonHandler the values are getting cut off after the first comma, So for example the value 16,275.38 would just get exported as 16. I'm not sure why this could be happening and how I could fix it? Or is there a better way of sorting the tooltip issue? Before the formatter it would show values as 16,275.3800000000023




Parents
  • 740
    Verified Answer
    Offline posted

    Hello Lewis,

    Thank you for posting in our community!

    I have been looking into your question and an approach I can suggest is using the IgxExcelExporter service columnExporting event. Then, inside the event handler, you can set the skipFormatter argument to true.

    This could look similar to the following:

    constructor(private excelExportService: IgxExcelExporterService) {
        this.excelExportService.columnExporting.subscribe((args) => {
            args.skipFormatter = true;
        });
    }

    Additionally, if you require additional modification on the exported data, this can be achieved via the rowExporting event.

    For example:

    constructor(private excelExportService: IgxExcelExporterService) {
        this.excelExportService.rowExporting.subscribe((args) => {
            args.rowData.quantity = parseFloat(args.rowData.quantity.toFixed(2));
        });
    }

    Please test this approach on your side and let me know if you need any further assistance regarding this matter.

    Sincerely,
    Riva Ivanova
    Software Developer

Reply Children