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

[Solved] Batch Edit; formatting; always saying changed!?

2 Answers 65 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.
Jeff Kershner
Top achievements
Rank 1
Jeff Kershner asked on 08 Dec 2011, 07:30 PM
I have an MVC3 Telerik Grid that does In Cell batch editing.  The columns RealForecast and RealActual are values are showing correctly formatted.  For example, the value is shown as "$0.00" before editing, "0" while editing, and "0" with a red carrot showing the value is changed when I click out of edit mode.

How do I get the value to not show it has change when it hasn't and how to I reapply the formatting?

Here is my grid markup:
@(Html.Telerik().Grid(Model.spendDetail).Name("spendGrid")
    .ClientEvents(clientEvents => clientEvents.OnDataBinding("dataBinding"))
    .DataKeys(keys =>
        {
            keys.Add(p => p.SpendVendorID);
        })
    .ToolBar(commands => { commands.SubmitChanges(); })
    .Columns(columns =>
    {
        columns.Bound(o => o.SpendDate).Format("{0:dd-MMM}");
        columns.Bound(o => o.SpendDate).Format("{0:ddd}");
        columns.Bound(o => o.RealForecast).Format("{0:C}");
        columns.Bound(o => o.RealActual).Format("{0:C}");
    })
 
    .DataBinding(data => data.Ajax().Enabled(true)
        .Select("_SpendDetailSelect", "SpendDetail")
        .Update("_SaveBatchEditing", "SpendDetail")
    )
    .Editable(editing => editing.Mode(GridEditMode.InCell))
    .Sortable()
    .Scrollable()
    .Pageable()
    .Footer(true)
)

Here is my model (RealForecast is the property I am binding to which is  Forecast divided by 100:
[Required]
public int Forecast { get; set; }
 
[DisplayName("Forecast")]
[DataType(DataType.Currency)]
public decimal RealForecast
{
    get
    {
        return Convert.ToDecimal(Forecast) / (decimal)100.0;
    }
 
    set
    {
        Forecast = Convert.ToInt32(value * (decimal)100.0);
    }
}




2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 12 Dec 2011, 12:50 PM
Hello Jeff Kershner,

This behavior is probably because you are not using the Currency editor template.

Currency.cshtml

@model decimal
 
@(Html.Telerik().CurrencyTextBox()
        .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty))
        .InputHtmlAttributes(new {style="width:100%"})
        .MinValue(0)
        .Value(Model)
)


I also attached a project implementing the expected correct behavior. I hope this helps.

Greetings,
Petur Subev
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
Jeff Kershner
Top achievements
Rank 1
answered on 12 Dec 2011, 05:42 PM
Awesome, thanks!
Tags
Grid
Asked by
Jeff Kershner
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Jeff Kershner
Top achievements
Rank 1
Share this question
or