This is a migrated thread and some comments may be shown as answers.
Grid storing the first row values as defaults
1 Answer 15 Views
This is a migrated thread and some comments may be shown as answers.
Raghu
Top achievements
Rank 1
Raghu asked on 25 Jan 2018, 08:28 PM

Hi Team,

I am facing problem in cancelling the grid with Inline Edit. Currently I have a grid that displays ApplicationName and AccessLevelvalues when we click edit and update this grid is working fine. But When I click edit and cancel it, my name field for any other rows will be getting replaced with ApplicationName of first row.. My code snippet is

<div style="position:relative;">
    <div style="float:left;position:relative; width:200px;">
        <label>UserName:</label>
        @(Html.Kendo().DropDownList()
                        .Name("Users")
                        .DataTextField("FullNameLastFirstMiddle")
                        .DataValueField("UserGuid")
                        .DataSource(source =>
                        {
                            source.Read(read =>
                            {
                                read.Action("GetUsers", "User");
                            });
                        })

        //.Events(e => e.Select("Dummy"))
        .Events(e => e.Change("OnUserChange"))
        .SelectedIndex(0)

        )
    </div>
    <div style="float:left;width:100%; position:relative;padding:10px;">
        @(Html.Kendo().Grid<MODEL>()
      .Name("grid")
      .AutoBind(false)
      .Scrollable(sc => sc.Height(250))
      .Columns(columns =>
      {

          columns.Bound(a => a.UserGuid).Hidden();
          columns.Bound(a => a.ApplicationName);

          columns.Bound(a => a.AccessLevelName).EditorTemplateName("AccessLevelList");
          /////

          columns.Command(commands => { commands.Edit(); }).Width(100);
      })
         .Editable(editable => editable.Mode(GridEditMode.InLine)) // Use inline editing mode.
         .HtmlAttributes(new { style = "height:400px;" })

         .DataSource(ds => ds
            .Ajax()
            .PageSize(10)
            .ServerOperation(false)

            .Read(read => read.Action("GetApplicationGrid", "User").Data("ApplicationAccessData"))
            .Model(model =>
            {
                model.Id(app => app.UserGuid);

                model.Field(app => app.ApplicationName).Editable(false);
                model.Field(app => app.AccessLevelGuid).Editable(false);
                // Make the application name property not editable.
            })
                .Events(events => events.Sync("KendoGridfresh"))
            .Update(update => update.Action("UpdateAccess", "User")

            )
            )

        )
    </div>
</div>

<script>
    var appItem;
    function KendoGridfresh() {
        var grid = $("#grid").data("kendoGrid");
        grid.dataSource.read();

    }

    function OnUserChange(e) {
        appItem = this.value();
        var grid = $("#grid").data("kendoGrid");
        grid.dataSource.read();
        grid.refresh();
    }
    function ApplicationAccessData(e) {
        var item = appItem
        return { item: item }
    }
</script>

 

1 Answer, 1 is accepted

Sort by
0
Raghu
Top achievements
Rank 1
answered on 25 Jan 2018, 09:37 PM
Found my solution here
https://www.telerik.com/forums/cancelling-inline-edit-changes-value-of-row-to-the-first-item-in-grid
Tags
Grid
Asked by
Raghu
Top achievements
Rank 1
Answers by
Raghu
Top achievements
Rank 1
Share this question
or