Articles in this section
Category / Section

How to replace number with text or date in Pivot Table?

1 min read

This article explains how to replace numbers with text or dates in a Pivot Table. You can display the text or date instead of a number in a JavaScript Pivot Table using the load event. Refer to the following code snippet.

Typescript

 let pivotGridObj: PivotView = new PivotView({ 
    dataSource: { 
        enableSorting: true, 
        columns: [{ name: 'Year' }], 
        values: [{ name: 'Sold', caption: 'Units Sold' }, { name: 'Amount', caption: 'Sold Amount' }], 
        data: getPivotData(), 
        rows: [{ name: 'Month' }], 
        formatSettings: [{ name: 'Month', format: 'MMM', type: 'date' }], 
        expandAll: false, 
        filters: [] 
    }, 
    load: (): void => { 
      for (let i: number = 0; i < pivotGridObj.dataSource.data.length; i++) { 
        let date: Date = new Date(); 
        date.setMonth(pivotGridObj.dataSource.data[i]["Month"] - 1); 
        pivotGridObj.dataSource.data[i]["Month"] = date; 
      } 
    }, 
    width: '100%', 
    height: 300, 
    gridSettings: { columnWidth: 140 } 
}); 
pivotGridObj.appendTo('#PivotView1'); 
 

 

In the example code, the JavaScript Date Object method ‘setMonth‘ has been used to convert the number into a month format and assign it to the date field.

Using formatSettings, you can set any date format for the date field.

 

Actual Pivot Table:

JavaScript Actual Pivot Table

 

After Customization:

JavaScript Pivot Table Customized

 

Stackblitz Example: https://stackblitz.com/edit/kbqh7w?file=index.ts

Github Example: How-to-convert-number-into-month-format-in-PivotGrid



Conclusion

We hope you enjoyed learning on how to replace number with text or date in Pivot Table.

You can refer to our JavaScript Pivot Table feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our JavaScript Pivot Table example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsBoldDesk Support, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied