Grid with edit popup

3 posts, 1 answers
  1. Christian Sandöy
    Christian Sandöy avatar
    17 posts
    Member since:
    Aug 2005

    Posted 29 Mar Link to this post

    @(Html.Kendo().Grid<intranet.mvc5b.Models.Arrangement.Lokaler>()
                .Name("gridLokaler")
                .Columns(col =>
                {
                    col.Bound(p => p.ID).Hidden(true);
                    col.Bound(p => p.Lokale);
                    col.Bound(p => p.Aktiv).Width(60).ClientTemplate("#=Aktiv? 'Ja' : 'Nej' #");
                    col.Command(command => { command.Edit()
                        .Text("Ret")
                        .UpdateText("Gem")
                        .CancelText("Afbryd");
                    }).Width(90);
                })
                .ToolBar(toolbar => toolbar.Create().Text("Opret lokale"))
                .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("arrLokaleEdit"))
                .Pageable()
                .DataSource(dataSource => dataSource
                    .Ajax()
                    .ServerOperation(false)
                    .PageSize(15)
                    .Events(events => events.Error("error_handler"))
                    .Model(model => model.Id(p => p.ID))
                    .Update("Lokaler_Update", "Arrangement")
                    .Create("Lokale_Opret", "Arrangement")
                    .Read("Lokale_Read", "Arrangement")
                )
                .Deferred()
            )

    This grid shows ok, but when I edit a row and save without making any changes

    it calls the create action insted of update

    Im using 2017.1.223.545

  2. Answer
    Viktor Tachev
    Admin
    Viktor Tachev avatar
    1789 posts

    Posted 30 Mar Link to this post

    Hello Christian,

    The behavior you describe can be replicated if you are editing an item where the ID is 0. This is the default value for numeric fields and when the value matches the default DataSource will consider the item new. 

    In order to change the behavior you can customize the DefaultValue to someting different. The code snippet below illustrate the approach:


    .Model(model =>
    {
        model.Id(p => p.ProductID);
        model.Field(p => p.ProductID).DefaultValue(-1);
    })


    Regards,
    Viktor Tachev
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Christian Sandöy
    Christian Sandöy avatar
    17 posts
    Member since:
    Aug 2005

    Posted 30 Mar in reply to Viktor Tachev Link to this post

    Adding a default value helped

    Thank you

Back to Top