This is a migrated thread and some comments may be shown as answers.

Parse number of month to string name

1 Answer 43 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
alex
Top achievements
Rank 1
Iron
Veteran
alex asked on 07 Jan 2021, 02:06 PM

how can i display month names without converting each month number via a function

this is my kendo grid with month column:

<kendo-grid-column field="month">
        <ng-template kendoGridCellTemplate let-dataItem="dataItem">
                <span>{{convertMonthNToName(dataItem)}}</span>
        </ng-template>
</kendo-grid-column>

the function convertMonthNToName contains a switch that returns a string month name

Is there anything kendo preset that does this? via a parse or via culture libraries

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 11 Jan 2021, 08:14 AM

Hi Alex,

Thank you for the provided code snippet.

In case the convertMonthNToName function receives a plain number, the most straight forward approach is to create an array with month names, and based on the number, to extract the right one, e.g.:

 <kendo-grid-column field="ProductID" title="ID" width="100">
        <ng-template kendoGridCellTemplate let-dataItem="dataItem">
          <span>{{ monthNames[dataItem.ProductID] }}</span>
        </ng-template>
      </kendo-grid-column>
  public monthNames = [
    "",
    "January",
    "February",
    "March",
    "April",
    "May",
    "June",
    "July",
    "August",
    "September",
    "October",
    "November",
    "December"
  ];

https://stackblitz.com/edit/angular-1rmayp?file=app/app.component.ts

However please check the following article related to build-in date/number parsing and formating options:

https://www.telerik.com/kendo-angular-ui/components/globalization/internationalization/parsing-and-formatting/

I hope this helps.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
alex
Top achievements
Rank 1
Iron
Veteran
Answers by
Martin
Telerik team
Share this question
or