user1852574
user1852574

Reputation: 104

Save changes to DB on editing a Kendo grid column

I want to save changes made in Kendo grid column. My grid doesn't have edit/update buttons. Requirement is such that I drag and drop a parameter in one of the rows, display the parameter name in the row, assign an ID to this row and call API to save data to the DB. I am not sure how to pass on this Grid data to the API call. I should either send the entire grid's form data to the API or the edited row data alone as form data to API. Please help me in doing this.

After dropping the parameter on to the Kendo grid, I am calling a function which is similar to below:

e.dropTarget.find(".class_name _of_the_row").text($(e.draggable.currentTarget).text());
var currentRow = e.dropTarget.closest(".grid_name").data("kendoGrid").dataItem(e.dropTarget);
var parameterId = e.draggable.element.attr("formulaparameter_id");
var parameterName = e.draggable.element.text();

currentRow.FormulaParameterName = parameterName;
currentRow.FormulaParameterId = parameterId;        

$.ajax(
{        
    url: "api/apiname",
    type: "PUT",
    dataType: "json",
    data: currentRow,
    success: function (data)
    {
        //refresh grid
    }
});

Passing currentRow as data is throwing exception as "Cannot read property 'field' of undefined"

Upvotes: 0

Views: 1513

Answers (1)

Rohan Kumar
Rohan Kumar

Reputation: 40639

This may be the fact that the toJSON() method is not recursive here. So, try this,

$.ajax({        
    url: "api/apiname",
    type: "PUT",
    dataType: "json",
    data: currentRow.toJSON(),//use toJSON here
    success: function (data) {
        //refresh grid
    }
});

Upvotes: 1

Related Questions