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

ClientTemplate for columns with Decimal data

1 Answer 1276 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Puzenat
Top achievements
Rank 1
Puzenat asked on 18 Dec 2012, 05:06 PM

Hello ,

I have a kendoGrid in form with different clientTemplate like this :

@using (Ajax.BeginForm("edition","activites",null,new { id = id + "formSaisieHeures", width = "100%" }))
    {
 @(Html.Kendo().Grid<Integraal.Models.Activite>()
    .Name(id+"GrilleSaisieHeures")
    .Columns(columns =>
    {
        columns.Bound(p => p.rowId)
            .ClientTemplate("#= rowId #" + "<input type='hidden' name='Activites[#= index(data)#].rowId' value='#= rowId #' />")
            .Hidden();
        columns.Bound(p => p.date)
            .ClientTemplate("#= kendo.toString(date,'d') #" + "<input type='hidden' name='Activites[#= index(data)#].date' value='#= kendo.toString(date,'dd/MM/yyyy') #' />")
            .Width(100);
        columns.Bound(p => p.client.code)
            .ClientTemplate("#= client.code #" + "<input type='hidden' name='Activites[#= index(data)#].client.code' value='#= client.code #' />")
            .Width(100);
        columns.Bound(p => p.client.raisonSociale)
            .ClientTemplate("#= client.raisonSociale #" + "<input type='hidden' name='Activites[#= index(data)#].client.raisonSociale' value='#= client.raisonSociale #' />")
            .Width(150);
        columns.Bound(p => p.affaire.code)
            .ClientTemplate("#= affaire.code #" + "<input type='hidden' name='Activites[#= index(data)#].affaire.code' value='#= affaire.code #' />")
            .Width(100);
        columns.Bound(p => p.affaire.mnemonique)
            .ClientTemplate("#= affaire.mnemonique #" + "<input type='hidden' name='Activites[#= index(data)#].affaire.mnemonique' value='#= affaire.mnemonique #' />")
            .Width(150);
        columns.Bound(p => p.heures)
                //.ClientTemplate(Html.Kendo().NumericTextBox<Decimal>()
                //        .Name("Activites[#=index(data)#].heures")
                //        .HtmlAttributes(new { type = "hidden", value = "#=heures#" })
                //        .Format("{n2}")
                //        .Decimals(2)
                //        .Min(0)
                //        .ToClientTemplate().ToHtmlString()
                // )
                 
            .ClientTemplate("#= heures #" +
                    "<input type='hidden' name='Activites[#= index(data)#].heures' value='#= heures #' data-format='n2' data-decimals='2' data-step='0.01' data-role='numerictextbox' />")                                  
                //.ClientGroupFooterTemplate("Heures : #=sum#")               
                .Width(100);
        columns.Bound(p => p.deplacement)
            .ClientTemplate("#= deplacement #" + "<input type='hidden' name='Activites[#= index(data)#].deplacement' value='#= deplacement #' />")
                .Width(100);
        columns.Bound(p => p.zone)
            .ClientTemplate("#= zone.libelle #" + "<input type='hidden' name='Activites[#= index(data)#].zone.code' value='#= zone.code #' />")
                .Width(150);
        columns.Command(command => command.Destroy()).Width(30);       
    })
        .Events(events => events.DataBound("onDataBoundSaisieHeures"))
        .ToolBar(toolbar =>
        {
            toolbar.Create();
        })
    .Resizable(resize => resize.Columns(true))
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Selectable(selectable => selectable.Mode(GridSelectionMode.Multiple))
    .Sortable()
    .Scrollable()
    .Navigatable() // Permet de changer de cellule en édition par exemple ! ;-)
    .Groupable()
    .DataSource(dataSource => dataSource
        .Ajax()
        .Aggregates(aggregates =>
        {
            aggregates.Add(p => p.heures).Sum();
        })
         
        .Batch(true)
        .ServerOperation(false)
        .Model(model =>
            {
                model.Id(p => p.rowId);
                // On indique des valeurs par défaut pour le bind des objets sinon erreur.
                model.Field(p => p.client).DefaultValue(
                     new Integraal.Models.ActiviteClientViewModel
                    {
                        code = "",
                        raisonSociale = ""
                    }
                );
                model.Field(p => p.affaire).DefaultValue(
                     new Integraal.Models.Affaire
                    {
                        code = "",
                        mnemonique = ""
                    }
                );
                model.Field(p => p.zone).DefaultValue(
                        new Integraal.Models.Zone
                        {
                            code = "",
                            libelle = ""
                        }
                );
            })
        .Read(read => read.Action("editing_read", "activites").Data("additionalDataRead"))
    )
)

 

my problems is on the columns "heures", i need to send a Decimal value to the controller.
my models "Activite" have correct data type for the columns "heures"
[DisplayName("Heures")]
[UIHint("Decimal")]
[DisplayFormat(DataFormatString = "{n2}")]
public Decimal heures { get; set; }

my input value is good in the html
(exemple : <input type="hidden" data-role="numerictextbox" data-step="0.01" data-decimals="2" data-format="n2" value="6.66" name="Activites[1].heures">)

"<input type='hidden' name='Activites[#= index(data)#].heures' value='#= heures #' data-format='n2' data-decimals='2' data-step='0.01' data-role='numerictextbox' />"

 


But in my controller the activite.heures is always at 0 -_-'
all others values are set correctly except heures
 

[HttpPost]
public PartialViewResult Edition(Activite activite)
{
List<Activite> edited = new List<Activite>();
List<Activite> deleted = new List<Activite>();
...

someone have any idea ?

 

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 20 Dec 2012, 05:37 PM
Hi,

The decimal value will not be parsed by the model binder if the application culture uses comma as decimal separator. If that is the case, then you should format the value set to the hidden input. This can be done by setting the Kendo culture like described in the globalization documentation and using the kendo.toString or kendo.format methods e.g.

value='#= kendo.toString(heures, \"n2\")#'
Regards,
Daniel
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Puzenat
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or