2012-12-23 28 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(); 
    } 
}