在编辑Kendo网格列时保存对DB的更改

时间:2014-08-12 06:08:58

标签: jquery kendo-grid

我想保存在Kendo网格列中所做的更改。我的网格没有编辑/更新按钮。要求是我将参数拖放到其中一行中,在行中显示参数名称,为该行分配ID并调用API以将数据保存到DB。我不知道如何将此网格数据传递给API调用。我应该将整个网格的表单数据作为表单数据发送到API或编辑的行数据到API。请帮我这样做。

将参数放到Kendo网格后,我调用的函数与下面的类似:

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
    }
});

传递currentRow作为数据抛出异常为"无法读取属性'字段'未定义"

1 个答案:

答案 0 :(得分:1)

这可能是toJSON() method在这里没有递归的事实。所以,试试这个,

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