我使用一個網格與自定義編輯器。我用colum內的textarea替換常見的輸入。劍道網格取消按鈕丟失新值
USECASE:
- 焯芬textarea的電流值作爲 「測試0」 一格的
- 按下編輯鍵(它的行)
- 添加新的價值 「測試01」
- 新聞網格更新按鈕
- 檢查網格行中更新的新值(工作)
- 再次按網格編輯按鈕(新值爲「test 01」)
- 按取消按鈕的網格(這裏有一些魔術heppens!並且不僅包含網格,而且包含每個定製編輯元素)
- 檢查當前值是否從「測試01」變爲「測試0」(失敗)。
取消之前的值(「測試0」而不是「測試01」)通過網格顯示。 這種情況與來自其他列(不是customEditable)的值相同。量。如果我保存,然後按取消,則顯示錯誤的值,但正確的價值觀會在數據庫保存
滿格重裝節省情況,但它不是最佳的AJAX電網
網格的數據源:
// bind json result from /Bonuses/GetPagedJsonBonuses
var bonusesDataSource = new kendo.data.DataSource({
transport: {
read: "@Url.Action("GetPagedJsonBonuses", "Bonuses")",
update: {
url: "@Url.Action("Edit", "Bonuses")",
type: "PUT"
},
create: {
url: "@Url.Action("Create", "Bonuses")",
type: "POST"
},
parameterMap: function(options, operation) {
if (operation === "update" || operation === "create") {
// updates the BonusDTO.EmployeeId with selected value
if (newValueEmployeeId !== undefined)
options.EmployeeId = newValueEmployeeId;
}
return options;
}
},
schema: {
data: "Data", // PagedResponse.Data
total: "TotalCount", // PagedResponse.TotalCount
model: {
id: "BonusId", // Data
fields: {
EmployeeId: { type: "number" },
EmployeeLastName: {
type: "string",
editable: true,
//validation: { required: {message: "Employee's last name is required"}}
},
Amount: {
type: "number",
editable: true,
nullable: false,
validation: {
required: { message: "Amount is required to be set" }
}
}
} // fields
} // model
}// schema
});
Grid元素看起來是這樣的:
// creates bonuses grid control
$("#bonusesGrid").kendoGrid({
dataSource: bonusesDataSource,
toolbar: ["create"],
editable: "inline",
columns: [
"BonusId",
"EmployeeId",
{
field: "EmployeeLastName",
editor: employeeAutocompletingEditor,
template: "#=EmployeeLastName#"
},
"Amount",
{
field: "Comment",
titel: "Comment",
editor: textareaEditor,
filterable: {
operators: {
number: {
contains: "Contains"
}
}
}
},
{
command: ["edit"],
title: " "
}
],
save: function(e) {
if (newValueEmployeeId !== undefined && newValueEmployeeLastName !== undefined) {
e.model.EmployeeId = newValueEmployeeId; // it's a hack to bind model and autocomplete control
e.model.EmployeeLastName = newValueEmployeeLastName;
}
},
edit: function(e) {
setCurrentValueEmployeeIdAndLastName(e.model.EmployeeId, e.model.EmployeeLastName);
},
cancel: function(e) {
setCurrentValueEmployeeIdAndLastName(e.model.EmployeeId, e.model.EmployeeLastName);
}
});
textarea的代碼是在這裏:
function textareaEditor(container, options) {
$('<textarea data-bind="value: ' + options.field + '" cols="10" rows="4"></textarea>')
.appendTo(container);
}
UPDATE 1
後步驟4(變化 '測試0' 至 '測試01' 註釋並按更新) 我有下一個請求:
Accept:application/json, text/javascript, */*; q=0.01
Content-Length:490
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost
Origin:http://localhost
Referer:http://localhost/
X-Requested-With:XMLHttpRequest
機構POST
Form Dataview sourceview URL encoded
BonusId:45
EmployeeId:47
Employee[EmployeeId]:47
Employee[UserName]:opetriv
Employee[LastName]:Oleh Petrivskyy
Employee[LastNameUkr]:Петрівський Олег Миронович
EmployeeLastName:Oleh Petrivskyy
Date:Fri Apr 19 2013 12:00:00
Amount:2
**Comment:test 01**
IsActive:true
Ulc:ryakh
Dlc:Fri Apr 19 2013 12:34:33 GMT+0300 (FLE Daylight Time)
它是正確的至於我。
來自控制器的響應是:
{"BonusId":45,
"EmployeeId":47,
"Employee":{"EmployeeId":47,"UserName":"opetriv","LastName":"Oleh Petrivskyy","LastNameUkr":"Петрівський Олег Миронович"},
"EmployeeLastName":"Oleh Petrivskyy","Date":"\/Date(1366362000000)\/","Amount":2,**"Comment":"test 01"**,"IsActive":true,"Ulc":"ryakh ","Dlc":"\/Date(1366375264603)\/"}
步驟7(按取消和接收此魔法)沒有任何AJAX請求到服務器之後。 我有一個數據源的錯誤處理程序,它不會觸發。
你如何更新服務器中的值?你在'schema.model'中定義了一個'id'嗎?是否有可能共享編輯原始文章或JSFiddle的一些代碼? – OnaBai
是的,我在我的模型中加入了一個id。代碼shered,對不起,但它是不可能的使用JSFiddle來模擬它 –