Parse number of month to string name

2 posts, 0 answers
  1. alex
    alex avatar
    17 posts
    Member since:
    Nov 2020

    Posted 07 Jan Link to this post

    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

     

     

     

     

  2. Martin
    Admin
    Martin avatar
    282 posts

    Posted 11 Jan Link to this post

    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/.

Back to Top