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

Grid with edit popup

2 Answers 62 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian Sandöy
Top achievements
Rank 2
Christian Sandöy asked on 29 Mar 2017, 01:10 PM

@(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 Answers, 1 is accepted

Sort by
0
Accepted
Viktor Tachev
Telerik team
answered on 30 Mar 2017, 02:08 PM
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.
0
Christian Sandöy
Top achievements
Rank 2
answered on 30 Mar 2017, 02:17 PM

Adding a default value helped

Thank you

Tags
Grid
Asked by
Christian Sandöy
Top achievements
Rank 2
Answers by
Viktor Tachev
Telerik team
Christian Sandöy
Top achievements
Rank 2
Share this question
or