This question is locked. New answers and comments are not allowed.
I'm trying to format a whole number (like 1234) in a MVC Grid so that it looks like 1,234
If I use
then it becomes 1,234.00
Is not supported (using Ajax binding).
I can get it to work with
However I use an extension to determine if the value is null. If so, we show N/A, if not, we use the format specified to display the value.
When I use the format ({0:###,###}) in combination with this method extension it fails with a javascript error (Illegal Character).
The same happens when I do this:
If I replace the # with 0 it works. So it looks like it cannot handle the # character. Might be because it is an escape character for Telerik? Any way to override this or another solution to use the # sign in an ClientTemplate?
If I use
.Format("{0:n}").Format("{0:n2}")I can get it to work with
.Format("{0:###,###}")However I use an extension to determine if the value is null. If so, we show N/A, if not, we use the format specified to display the value.
public static GridBoundColumnBuilder<T> DefaultToNA<T>(this GridBoundColumnBuilder<T> columnHelper) where T : class { const string defaultValue = "N/A"; var format = columnHelper.Column.Format ?? ""; if (!String.IsNullOrEmpty(format.Trim())) { columnHelper.ClientTemplate(string.Format("{0}", "<# if(" + columnHelper.Column.Member + " + ''.length == 0) { #>" + defaultValue + "<#;} else { #> <#= $.telerik.formatString('" + format + "', " + columnHelper.Column.Member + ") #> <#}#>")); } else columnHelper.ClientTemplate(string.Format("{0}", "<# if(" + columnHelper.Column.Member + " + ''.length == 0) { #>" + defaultValue + "<#;} else { #> <#=" + columnHelper.Column.Member + "#> <#}#>")); return columnHelper; }When I use the format ({0:###,###}) in combination with this method extension it fails with a javascript error (Illegal Character).
The same happens when I do this:
columns.Bound(o => o.CSO).ClientTemplate("<#= $.telerik.formatString('{0:###,###}', CSO) #>")If I replace the # with 0 it works. So it looks like it cannot handle the # character. Might be because it is an escape character for Telerik? Any way to override this or another solution to use the # sign in an ClientTemplate?