This sample demonstrates how to convert numeric month values into readable month names in the Syncfusion JavaScript Pivot Table (PivotView) component. It uses a client-side data source and updates the month values during the load event.
The Pivot Table (PivotView) is a powerful tool for summarizing and analyzing data. In this example:
- We use a data source with fields like
Month,Year,Country,Products,Sold, andAmount. - The
Monthfield initially contains numbers (1–12). - During the
loadevent, these numbers are converted into Date objects, and the Pivot Table displays them in short month format (e.g., Jan, Feb) usingformatSettings.
- Node.js (optional for running locally)
- A modern browser (Chrome, Firefox, Edge)
-
Clone the repository:
git clone https://github.com/SyncfusionExamples/How-to-convert-number-into-month-format-in-PivotGrid
-
Install dependencies:
npm install
-
Run the application:
npm start
This will open the app in your default browser using browser-sync.
-
Alternatively, open
index.htmldirectly in your browser.
- src/index.html – Main HTML page
- src/app/app.ts – PivotView configuration and month conversion logic
- src/styles/styles.css – Optional custom styles
- system.config.js – SystemJS configuration
- package.json – Scripts and dependencies
-
Custom Month Conversion:
TheMonthfield is converted from a number to a date object:load: function () { for (var i = 0; i < pivotGridObj.dataSource.data.length; i++) { var date = new Date(); date.setMonth(pivotGridObj.dataSource.data[i]["Month"]); pivotGridObj.dataSource.data[i]["Month"] = date; } }
-
Field Configuration:
- Rows:
Month - Columns:
Year - Values:
Sold(Units Sold),Amount(Sold Amount) - Formatting:
Monthdisplayed as short month (MMM),Amountin currency (C0)
- Rows:
For questions or feedback, visit the Syncfusion Support Portal or Community Forums.
This is a commercial product and requires a valid Syncfusion license.
View License Terms.