Kendo UI网格节省细胞模糊

时间:2012-12-23 15:38:30

标签: javascript jquery json gridview kendo-ui

当我按下Enter键或移出单元格(模糊)时,我试图让网格保存更改,而不必使用网格工具栏中的保存按钮。

我无法正常工作,我的PHP / SQL工作正常,所以我确定网格出了问题。

这是我的代码:

$("#grid").kendoGrid({
dataSource: {
    transport: {
        read: WEBROOT+"admin/fetch-toppers",
        update: {
            url: WEBROOT+"admin/update-topper",
            type: "POST"
        }
    },
    error: function(e)
    {
        alert(e.responseText);
    },
    schema: {
        data: "data",
        model: {
            id: 'id',
            fields: {
                "id": {nullable: true},
                "Date": {editable: false},
                "name": {editable: false},
                "price": {editable: true}
            }
        }
    }
},
columns: [{field: "Date", width: 105}, {field: "name", title: "Topper"}, {field: "price", title: "Price", width: 125}],
height: 550,
filterable: true,
sortable: true,
pageable: true,
editable: true,
navigatable: true,
edit: function()
{
    //this.saveChanges()
}
});

我尝试过很多事情和不同的事件,但没有效果。

如何在模糊时保存单元格值?

4 个答案:

答案 0 :(得分:7)

在您的DataSource中添加:

change: function (e) {
                        if (e.action == "itemchange") {
                            this.sync();
                        }
                    },

应该看起来像:

dataSource: {
transport: {
    read: WEBROOT+"admin/fetch-toppers",
    update: {
        url: WEBROOT+"admin/update-topper",
        type: "POST"
    }
},
error: function(e)
{
    alert(e.responseText);
},
change: function (e) {
                        if (e.action == "itemchange") {
                            this.sync();
                        }
},
schema: {
    data: "data",
    model: {
        id: 'id',
        fields: {
            "id": {nullable: true},
            "Date": {editable: false},
            "name": {editable: false},
            "price": {editable: true}
        }
    }
}

},

答案 1 :(得分:1)

您可以尝试使用dataSource的 change 事件来执行dataSource的 sync 方法。

   $("#grid").kendoGrid({
dataSource: {
    transport: {
        read: WEBROOT+"admin/fetch-toppers",
        update: {
            url: WEBROOT+"admin/update-topper",
            type: "POST"
        }
    },
    change:function(){this.sync()},
    error: function(e)
    {
        alert(e.responseText);
    },
    schema: {
        data: "data",
        model: {
            id: 'id',
            fields: {
                "id": {nullable: true},
                "Date": {editable: false},
                "name": {editable: false},
                "price": {editable: true}
            }
        }
    }
},
columns: [{field: "Date", width: 105}, {field: "name", title: "Topper"}, {field: "price", title: "Price", width: 125}],
height: 550,
filterable: true,
sortable: true,
pageable: true,
editable: true,
navigatable: true,
edit: function()
{
    //this.saveChanges()
}
});

答案 2 :(得分:0)

有一种更简单的方法可以实现此目的:在数据源上将autoSync设置为true:https://docs.telerik.com/kendo-ui/api/javascript/data/datasource/configuration/autosync

答案 3 :(得分:-1)

您还可以按如下方式从网格中调用数据源同步(确保使用setTimeout,根据Telerik在此post中)...

save: function () {
     setTimeout(function() {
          yourDatasource.sync();
     }
}