| <%= Html.Telerik().Grid<IrpGoalVM>() |
| .DataBinding(dataBinding => dataBinding.Ajax().Select("IrpGoals", "AccData", new {Id = Model.Id } )) |
| .Name("GoalGrid") |
| .PrefixUrlParameters(true) |
| .Columns(columns => |
| { |
| columns.Bound(g => g.Id).Visible(false); ; |
| columns.Bound(g => g.Type); |
| columns.Bound(g => g.Goal); |
| columns.Bound(g => g.GoalDate).Format("{0:dd MMM yyyy}").Title("Achieve by"); |
| columns.Bound(g => g.Responsibility); |
| columns.Bound(g => g.Completed).Format("{0:dd MMM yyyy}").Width(120); |
| columns.Bound(g => g.EstCost).Format("{0:c}"); |
| }) |
| .Pageable() |
| .Sortable() |
| %> |
This works fine with server side binding but not so well with ajax. With server side, the null dates get formated as an empty string, and the EstCost gets formated as currency. With ajax binding however null dates show as "null" and the EstCost has no formatting at all.
See attached.
How can I fix this?
Sean
15 Answers, 1 is accepted
Hi Sean,
Not sure if this would help, but Here is what I do for a date ajax side ...
columns.Add(o => o.cDateUpdated).Format(
"{0:MM/dd/yyyy}").Width(85).Title((string)Resources.BCAResources.stdUpdated);
If this helps, maybe if you look around for this Format date option, the currency won't be far behind ?
good luck.
| .ClientTemplate("<%#= NULLALBEDATECOLUMN #>".Replace("null", "")) |
to the end of my column binding.
Hi Sean,
Sorry, thought I saw something else in your formating.
Dont want to waste your time.
I believe that there are ways to check for null inside your ViewModel so that if the date from the data base is null, then you can change it to whatever you need. I never had to do that.
Another thought is RowAction. You might be able to initialize your date to a datetime if it is null, or format your date if it is null.
| /* After the data is bound to the Grid control, then it appears here. |
| * This happens also when page is loaded & after a click.*/ |
| .RowAction(row => |
| { // If the companyname.length>0, set row as selected. |
| rowrow.Selected = row.DataItem.cCompanyName.Length>0; |
| }) |
If that dosnt work, its an excellent shot. Is there a place that shows these types of properties or methods ? I keep seeing code like this , but I dont know where to go to find it ? I often see people propose solutions with code I never saw before.
Thanks Alan
| columns.Bound(g => g.Completed).Width(120).ClientTemplate("<#= Completed == null ? '' : (Completed).format('dd MMM yyyy') #>"); |
Now I just need to figure out what to do with the currency field.
Sean
Couldnt use the same statement and just change the formating to something for currency ?
| columns.Bound(g => g.Completed).Width(120).ClientTemplate("<#= Completed == null ? '' : (Completed).format('$ 00.00') #>"); // Something like that ? |
| THAT OF COURSE WONT WORK - BUT YOU GET THE IDEA |
| columns.Bound(g => g.GoalDate).Title("EC").ClientTemplate("<#= (EstCost).format('C') #>"); |
That displays the number as "¤500.00". Now I just need to replace "¤" with "$".
columns.Bound(g => g.EstCost).Title("EC").ClientTemplate("<#= (EstCost).format('C') #>");
Still has the "¤500.00" problem though.
http://www.telerik.com/community/forums/aspnet-mvc/general/format.aspx
columns.Add(o => o.OrderTotal).Format("{0:C}").Title("Total");
HeaderText="Order Total" DataFormatString="${0:C2}" DataField="OrderTotal" SortExpression="OrderTotal">
links i found on currency - you may have seen these already.
http://demos.telerik.com/aspnet-ajax/grid/examples/client/columnformatting/defaultcs.aspx
http://demos.telerik.com/mvc/forum/aspnet-ajax/grid/varying-currency-symbol
I would like to shed some light in this.
- "{0:c}" is not supported for the time being. This is mentioned in this help topic (number formatting is not currently supported in ajax binding). As a workaround you can create a ViewModel class and a string property which contains the formatted value (you will format it server side when performing the binding).
- Indeed during client-side binding we show null which is not so user friendly. I have fixed this. To use the fix open telerik.grid.js and replace this
if (column.format || column.type == 'Date')
return function(data) {
return value == null ? '' : $t.formatString(column.format || '{0:G}', column.value(data));
}
with this:
if (column.format || column.type == 'Date')
return function(data) {
var value = column.value(data);
return value == null ? '' : $t.formatString(column.format || '{0:G}', value);
}
Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.