Category / Section
How to replace number with text or date in Pivot Table?
1 min read
You can display the text or date instead of number in JavaScript Pivot Table using 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, JavaScript Date Object method ‘setMonth‘ has been used to convert the number as month format and assign it to the date field.
Using formatSettings, you can set any date format for the date field.
Actual Pivot Table:
After Customization:
Stackblitz Example: https://stackblitz.com/edit/kbqh7w?file=index.ts
Github Example: How-to-convert-number-into-month-format-in-PivotGrid
Conclusion
I 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 know 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!