Kendo UI Grid错误 - 未定义保存

时间:2014-03-06 14:51:37

标签: javascript kendo-ui kendo-grid

我有以下Kendo UI网格。我正在尝试从网格中提醒更新的值。但我收到了以下错误

  

未捕获的ReferenceError:未定义保存

我们如何解决此错误并显示网格中的所有更新值?

Fiddle

enter image description here

车身

<div id="grid"></div>
<br />
<input type="button" value="Save Row" onclick="save();" />
<input type="button" value="Submit To Server" onclick="" />

<script id="gridItems" type="text/x-kendo-template">
    <tr data-uid="#= uid #">
        <td title="#= EmpName #">
            #= EmpName #
        </td>
        <td title="#= Department #">
            #= Department #
        </td>
    </tr>
</script>

的Javascript

var records = [
    {
        "foo": 1,
         "EmpName":"A1",
         "Department": "D1"
    },
    {
        "foo": 2,
        "EmpName":"A2",
        "Department": "D2"
    }
              ];

var myDataSource = new kendo.data.DataSource({
    data: records,
    schema: {
        model: {
            id: "foo",
            fields: {
                    foo: {type: "number"},
                    EmpName: {type: "string"},
                    Department: {type: "string"}
                    }
                }            
            }
});

var grid = $("#grid").kendoGrid({
    dataSource: myDataSource,
    columns: ["EmpName", "Department"],
    editable: "inline",
    selectable: "row",
    rowTemplate: kendo.template($("#gridItems").html()),

    dataBound: function() 
    {
        //Click on each row
        $("#grid tbody tr").on("click", function(e) 
        {          
            if (!$(this).hasClass('k-grid-edit-row')) 
            {
                //Make the row editable
                $("#grid").data("kendoGrid").editRow($(this));
            }
        });
    }
}).data("kendoGrid");

function save() 
{
    var row = $("#grid tbody").find(".k-grid-edit-row"); 
    if(row.length == 1) 
    {
        $("#grid").data("kendoGrid").saveRow(row);
    }

    var updatedData = grid.dataSource.data();
    alert(updatedData.length);

    for (var i = 0; i < updatedData.length; i++) 
    {
       var dataitem = updatedData[i].EmpName;
       alert(dataitem);
    }


}

参考

  1. Grid / Batch editing
  2. Kendoui Grid Editing Tips and tricks
  3. Row-Template
  4. Pop-up Data Editing

1 个答案:

答案 0 :(得分:1)

将这样的点击功能绑定,而不是使用内联

<input type="button" id="saveVal" value="Save Row"  />

$('#saveVal').click(function (){
     save();
});

DEMO

在你的dom准备好之后把你的脚本放好,

DEMO2

enter image description here