Grid storing the first row values as defaults

2 posts, 0 answers
  1. Raghu
    Raghu avatar
    2 posts
    Member since:
    Nov 2017

    Posted 25 Jan 2018 Link to this post

    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>

     

  2. Raghu
    Raghu avatar
    2 posts
    Member since:
    Nov 2017

    Posted 25 Jan 2018 Link to this post

    Found my solution here
    https://www.telerik.com/forums/cancelling-inline-edit-changes-value-of-row-to-the-first-item-in-grid
Back to Top