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

[Solved] TelePhone Format

4 Answers 78 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
HaBo
Top achievements
Rank 1
HaBo asked on 02 Dec 2011, 04:58 PM
Can Any one help me how can i Format Telephone Number in Telerik MVC Grid.

this is my code
columns.Bound(e=>e.ID)
.ClientTemplate("<#= $.telerik.formatString('{0:###-###-###}',Telephone) #> <br /> <#= $.telerik.formatString('{0:###-###-###}',Fax) #> ").Title("Phone / Fax");

Above Code it Not working.

Any help would be greatly appreciated.

Thanks

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 06 Dec 2011, 06:04 PM
Hello Harsha,

To use the "#" character in a Template you should declare a JavaScript function which applies the formatting and call it from the template. For example:
columns.Bound(e=>e.ID)
    .ClientTemplate("<#= GetPhoneFaxTemplate(data) #>").Title("Phone / Fax");
     
<script type="text/javascript">
function GetPhoneFaxTemplate(data){
    var template = $.telerik.formatString('{0:###-###-###}',data.Telephone) + "<br/>" +
         $.telerik.formatString('{0:###-###-###}',data.Fax)
    return template;
}
</script>


Kind regards,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
HaBo
Top achievements
Rank 1
answered on 06 Dec 2011, 08:19 PM
No use. with the Function

function GetPhoneFaxTemplate(data) {
       var template = $.telerik.formatString('{0:###-###-####}', data.Telephone) + "<br/>" +
        $.telerik.formatString('{0:###-###-####}', data.Fax)
       alert(template);
       return template;
   }
alert gives me ########## <br /> ##########

it is not formatting as declared in statement 
$.telerik.formatString('{0:###-###-####}', data.Telephone)
0
Daniel
Telerik team
answered on 09 Dec 2011, 02:32 PM
Hi Harsha,

The $.telerik.formatString method accepts number as parameter. So if the Telephone and Fax fields
are Strings it will not work as expected.
I attached a project which demonstrates how to use the Template in such cases. I hope it helps.

Greetings,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
HaBo
Top achievements
Rank 1
answered on 09 Dec 2011, 03:33 PM
Thank you very much it helped me a lot
Tags
Grid
Asked by
HaBo
Top achievements
Rank 1
Answers by
Daniel
Telerik team
HaBo
Top achievements
Rank 1
Share this question
or