We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Date Formatting Problem

Good Afternoon.

In your documentation https://ej2.syncfusion.com/angular/documentation/pivotview/how-to/customize-number-date-and-time-values/ you say that we can customize date and time formatting. On preview tab i see that all dates have the same value (01/01/1970-02:00).



 formatSettings: [{ name: 'Sold', format: 'dd/MM/yyyy-hh:mm', type: 'date' }],


I need to make a pivot grid like this and i found out that the problem really exists.



The real date values are 18-06-2019 09:22, 18-06-2019 10:15 e.t.c.

6 Replies

JP Jagadeesan Pichaimuthu Syncfusion Team June 21, 2019 09:24 AM UTC

Hi Isaias, 
  
Currently, we don’t have option to format date in value axis directly using formatSettings. But, you can display the date in values by using aggregationCellInfo event. Please refer the following code snippet. 
 
Code Snippet: 
aggregateCellInfo(args) { 
    if (args.columnCellType == 'grandTotal') { 
      args.value = ''; 
      for (var i = 0i < args.cellSets.lengthi++) { 
        if (typeof (args.cellSets[i][args.fieldName]) == "number") { 
          args.value = args.value + args.cellSets[i][args.fieldName]; 
        } 
      } 
    } else if (args.cellSets[0]) { 
      args.value = args.cellSets[0][args.fieldName]; 
    } 
  } 
  
  
  
Note: We formatted the Sold Amount (Number) into the date in the document. Number regarded as count in this case. If the count is the same for all numbers, all values will display the same date. 
  
Please let us know if you need further assistance on this. 
  
Regards, 
Jagadeesan


IC Isaias Chalvatzoglou June 21, 2019 10:31 AM UTC

Hi Jagadeesan,

Problem solved.

Thank you for your quick response!




IC Isaias Chalvatzoglou June 21, 2019 10:50 AM UTC

Hello again.

When I'm exporting same pivot grid to excel, date saved in the excel as '2019-06-20T06:22:00'. There is a way datetime to be saved like the formatting i defined in format settings 'dd/MM/yyyy hh:mm' ?




JP Jagadeesan Pichaimuthu Syncfusion Team June 24, 2019 08:41 AM UTC

Hi Isaias, 
  
You can achieve your requirement using beforeExcelExport event. Please refer following code snippet. 
  
Code Snippet: 
dataBound(args): void { 
    this.pivotGridObj.grid.beforeExcelExport = function (args) { 
      var data = (args as any).gridObject.dataSource; 
      for (var i = 0i < data.lengthi++) { 
        for (var j = 0j < Object.keys(data[i]).lengthj++) { 
        if (data[i][j].axis == 'value') { 
          data[i][j].value = data[i][j].formattedText; 
        } 
      } 
    } 
  } 
} 
  
  
Please let us know if you need further assistance on this. 
  
Regards, 
Jagadeesan


IC Isaias Chalvatzoglou June 24, 2019 10:08 AM UTC

Hi Jagadeesan,

It works!

Thank you


DB Dinesh Babu Yadav Syncfusion Team June 25, 2019 06:12 AM UTC

Hi Isaias, 
 
Thanks for the update. Please get back to us if you need further other assistance from us. 
 
Regards, 
Dinesh Babu Yadav 


Loader.
Live Chat Icon For mobile
Up arrow icon