Read is never called, even after Save Changes

1 posts, 0 answers
  1. Samuel
    Samuel avatar
    19 posts
    Member since:
    Aug 2012

    Posted 18 Nov 2012 Link to this post

    I've been trying to figure out why my Grid gets out of date and noticed that even after a Save Changes, the grid doesn't call my Read action. If I click on Cancel Changes after I save the changes then all is well (but it still never calls the Read) so I'm at a loss as to why the results end up showing 'undetermined' if I don't click on Cancel Changes and if there's a way to force the page to do whatever it is that Cancel Changes is doing after a Save.

    Any ideas? My grid (which uses editor templates and a client template) is:
    @model IEnumerable<Datamart.Models.ViewModels.LEAFundMap>
     
    @{
        ViewBag.Title = "CreateFundMap";
        var snapshot = Session["snapshot_id"] ?? Request.Params["snapshot_id"];
    }
     
    <h2>CreateFundMap</h2>
    @(Html.Kendo().Grid(Model)
    .Name("Funds")
    .Columns(cols =>
        {
            cols.Bound(p => p.entity_fund).ClientTemplate("#=entity_fund#");
            cols.Bound(p => p.fund_desc).ClientTemplate("#=fund_desc.fund_desc#");
        })
    .ToolBar(commands =>
        {
            commands.Save();
        })   
    .Editable(edit => edit.Enabled(true).Mode(GridEditMode.InCell))
    .DataSource(ds => ds
                .Ajax()
                .Model(model =>
                    {
                        model.Id(p => p.entity_fund);
                        model.Field(p => p.entity_fund).Editable(false);
                         
                    })
                // Configure RU -->
                    .Read(read => read.Action("Fund_Read", "Draft").Data("additionalData"))
                    .Update(update => update.Action("Fund_Update", "Draft").Data("additionalData"))
                    //.ServerOperation(false)
                        .Batch(true)
                    .Events(events => events
                        //.Change("onChange") // commented out because it causes an infinite loop
                        .Error("onError")                   
                        )
                    )
                // <-- Configure RU
                 
                )
     
    <script>
    function additionalData() {
        return {
            snapshot_id: "@snapshot"
        };
    }
     
    function onError(e, status) {
        if (e.errors) {
            var message = "The following errors have occurred:\n";
     
            $.each(e.errors, function (key, value) {
                if (value.errors) {
                    message += value.errors.join("\n");
                }
            });
     
            alert(message);
        }
    }
     
    function onChange() {
        var grid = $("#Funds").data("kendoGrid");
     
        grid.dataSource.read();
    }
    </script>
Back to Top