This question is locked. New answers and comments are not allowed.
I am trying to format numeric columns in an ajax-bound grid using ClientTemplate and $.telerik.formatString following the instructions in this post. I do not receive an error - however the formatting does not work and always return the unformatted string. I debugged in firebug and it appears thwe issue comes from $.telerik.formatString() itself. It gets called properly, but returns an unformatted string. Stepping through the code (for instance with '{0:c}' and 1000 as parameters) I noticed the line this.formatters["number"] returns undefined. In fact the array has only one element - date - is this normal? Am I missing another script file which might have the missing formatters elements? Or are they not used, but then why isn't my data formatted properly?
Here is my code:
Javascript:
Here is my code:
public static GridColumnSettings ApplyFormat(this GridColumnSettings column, string format) { format = format.Replace("#", "^"); column.ClientTemplate = "<#= formatter('" + format + "', " + column.Member + ") #>"; return column; }Javascript:
function formatter(format, value) { format = format.replace(/\^/g, '#'); return $.telerik.formatString(format, value); } And the formatString() that is called from telerik.common.min.js:
formatString:function() { var w = arguments[0]; for(var e=0,t=arguments.length-1;e<t;e++) { var v = new RegExp("\\{" + e + "(:([^\\}]+))?\\}","gm"); var u = arguments[e + 1]; var x = this.formatters[this.getType(u)]; if(x) { var y = v.exec(w); if(y) { u = x(u,y[2]) } } w = w.replace(v,function() { return u }) } return w }I tried with the following formats: "{0:n}" , "{0:c}", "{0:##,###}" to no avail. Any idea what I might be doing wrong? I am using MVC3 with Razor and the latest build of the Telerik extensions for MVC (2011.1.523).
Thanks in advance!