2012-12-23 23 views
5

我想让我的网格保存更改,当您按下输入或移走单元格(模糊),而不必使用网格工具栏中的保存按钮。Kendo UI网格保存在单元格模糊

我很难让它正常工作,我的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() 
} 
}); 

我已经尝试了很多事情,不同的事件,但它没有任何效果。

如何获取它以保存单元格模糊值?

回答

7

在您的数据源中添加:

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

},

+0

谢谢你!!!!! – imperium2335

+0

优秀!谢谢!在剑道论坛有许多线索需要看到这个! – zerodahero

1

你可以尝试使用数据源的change事件来执行数据源的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() 
} 
}); 
+0

我该如何放入我拥有的环境? – imperium2335

+0

请您澄清一下吗? –

+0

如何更改我的代码以实现您的建议?我已经尝试了一切,但仍然无法正常工作,但保存更改按钮可以正常工作,但这不是我想要的。 – imperium2335

0

您也可以拨打您的数据源同步,从一格如下(确保你使用setTimeout,按照这个post中的Telerik)...

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