0
votes

I am using Inline editing in a Kendo Grid and I want to be able to get the current row data when doing an update.

Html.Kendo().Grid<WheresMyTool.Models.COMPANYADDRESS>()
        .Name("ShipToLocationsGrid")
        .Editable(editable => editable.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
        .Pageable(pager => pager.PageSizes(new List<object> { 5, 10, 20, 100 }))
        .DataSource(dataSource => dataSource
            .Ajax()
            .Model(model => model.Id(p => p.COMPANY))
            .Read(read => read.Action("IndexShipToLocations", "Company", new { company = Model.company  }))
            .Update(update => update.Action("ShipToLocations_Update"))
            .PageSize(20)
        ) 

Here is my update method

public ActionResult ShipToLocations_Update([DataSourceRequest] DataSourceRequest request, COMPANYADDRESS ca)
        {
            Repository repo = new Repository();
            repo.UpdateCompanyAddressRecord(ca, username);
            return Json(ca);
        }

I want to be able to access the current data. It seems like only the modified data is passed in.

1
What do you mean by access the current data? Current from your view model, or current from your database model? Your COMPANYADDRESS should be a view model that is being passed to your Controller method ShipToLocations_Update(). This takes in your view model then updates the corresponding model in your data. - Kevin
I was hoping to get the data in the selected row from the grid. - Brian Kalski
I posted an edit in my answer to address your comment. - Kevin

1 Answers

0
votes
[HttpPost]
    public ActionResult EditTestStationInLine([DataSourceRequest] DataSourceRequest request, TestStationViewModel tsvm)
    {
        if(tsvm != null && ModelState.IsValid)
        {
            TestStation ts = _testStationService.Find(tsvm.Id);
            ts.ProductionLineId = tsvm.ProductionLineId;
            ts.ProdLine = _productionLineService.Find(tsvm.ProductionLineId);
            ts.Name = tsvm.Name;

            _testStationService.Update(ts);

            tsvm.Id = ts.Id;
            tsvm.ProductionLineId = ts.ProductionLineId;
        }

        return this.Json(new[] { tsvm }.ToDataSourceResult(request, ModelState));
    }

This is an example of one of my InLine edits. Your view model is used to create a database model. Once your database model is created, you can pass back the hidden attributes, in my case the Id and CreateAt. Hope this helps answer your question.

Edit:

function Edit(e) {
    var grid = $('#NAMEOFKENDOGRID').data('kendoGrid');
    var dataItem = grid.dataItem($(e.target).parents('tr'))
    var id = dataItem.id;
    $.ajax({//Makes an ajax call
        success: function (data) {
            $('#NAMEOFDIV').load("/Controller/Update/" + id);
        }
    });
}

You can make a custom command, conveniently called Edit, which then gets the Id from that row. It also makes an ajax call to your update method. Modify the ajax to fit your needs.