Number Formatting

6 posts, 1 answers
  1. Ian
    Ian avatar
    21 posts
    Member since:
    Apr 2011

    Posted 02 Dec 2011 Link to this post

    Hi,
    We have 10 digit phone numbers coming from a database (as numerical types, not strings) and I want to format them in the kendo grid. I can't seem to find the right formatting string. Any ideas?
    Thanks,
    ian
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 05 Dec 2011 Link to this post

    Hi Ian,

    Could you please elaborate more on this? What is the require format ? 

    Regards,
    Georgi Krustev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. Ian
    Ian avatar
    21 posts
    Member since:
    Apr 2011

    Posted 05 Dec 2011 Link to this post

    Hi,
    Thanks for your interest. As an example, my viewmodel is returned from the server and has a phone field with a value 5553242345. I would like to bind this to a text input such that it is masked (555) 324-2345, and bind it to a label with the same format. In the past we have used a custom binding in knockout.js to perform this. Ideally, it would be great for the binding to automatically translate the value of the input from the masked/raw format.

    Thanks again,
    ian
  5. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 07 Dec 2011 Link to this post

    Hello Ian,

     
    In order to achieve your goal you will need to create a function, which will format the number into
    "(###) ###-####" format. Once you have this function, you will be able to use it in the template to format the number:

    function format(number) {
     //return formatted number;
    }
     
    var inlineTemplate = kendo.template("The number is #= format(number) #.");
    var inlineData = { number: 1234567890 };
     
    $("#inline").html(inlineTemplate(inlineData));

    I am not expert in knockout.js, but I believe that you should create a value converter. Check this article for more information.

    Regards,
    Georgi Krustev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Ian
    Ian avatar
    21 posts
    Member since:
    Apr 2011

    Posted 07 Dec 2011 Link to this post

    Thanks Georgi,
    Yeah, this is actually what we ended up with. I was hoping for a bit of a cleaner syntax within our templates (where don't have to tote around a big list of functions from project to project simply for the equivalent of string.format function. I was hoping that kendo.toString(... function would support a custom formatter. 

    Thanks,
    ian
  7. Gary
    Gary avatar
    14 posts
    Member since:
    Jan 2012

    Posted 10 Apr 2012 Link to this post

    Is it the case that any inline template that includes the '#' character needs to be externalized into a function. When I have an inline grid column template like:

    '#= kendo.toString(number, "##,#") #'

    I get an 'invalid template' error.
Back to Top
Kendo UI is VS 2017 Ready