我正在更新数据库中的网格值。并将值从CS页面传递给JSgrid。删除,编辑完全适用于db。但是在搜索之后网格没有得到更新。我可以将搜索值传递给CS页面并从DB获取相应的搜索值。但是这些值没有得到JSgrid的更新。
var Status;
var lastPrevItem;
var clients =<%=gridData%>
$("#jsGrid").jsGrid({
width: "100%",
height: "450px",
filtering: true,
//filterable:true,
//inserting: true,
autosearch: true,
editing: true,
sorting: true,
paging: true,
autoload: true,
pageSize: 25,
pageButtonCount: 5,
deleteConfirm: "Do you really want to delete the Department?",
controller: //db,
{ loadData: function (filter) {
if (filter["ID"] != "" || filter["Name"] != "") {
return $.ajax({
type: "POST",
async: true,
processdata: false,
paging: true,
contentType: "application/json; charset=utf-8",
url: "myurl/mycsmethod",
data: "{'ID':'" + filter["ID"] + "','Name':'" + filter["Name"]+ "'}",
success: function (data) {
},
error: function (XHR, errStatus, errorThrown) {
var err = JSON.parse(XHR.responseText);
errorMessage = err.Message;
alert(errorMessage);
}
});
}
},
updateItem: function (clients) {
var result = $.Deferred();
alert(result);
var ajaxDeferred = $.Deferred().reject();
alert(ajaxDeferred);
ajaxDeferred.done(function (updatedItem) {
result.resolve(updatedItem);
}).fail(function () {
result.resolve(lastPrevItem);
});
return result.promise();
},
},
onItemDeleting: function (args) {
//its working fine
},
onItemEditing: function (args) {
//its working fine
},
data: clients,
fields: [
{ type: "control" },
{ name: "ID", visible: false, width: 0, validate: "required" },
{ name: "Name", visible: false, width: 0, validate: "required" },
]
});
我要更新&lt;%= gridData%&gt;触发搜索按钮后使用jsgrid。
答案 0 :(得分:0)
loadData: function(filter) {
return $.grep(clients, function(client) {
return (!filter["DeptID"] || client["DeptID"].indexOf(filter["DeptID"]) > -1)
&& (!filter["DeptName"] || client["DeptName"].indexOf(filter["DeptName"])>-1)
&& (!filter["Status"] || client["Status"].indexOf(filter["Status"]) > -1)
});},
updateItem: function (updatingClient) {
var result = $.Deferred();
alert(result);
var ajaxDeferred = $.Deferred().reject();
alert(ajaxDeferred);
ajaxDeferred.done(function (updatedItem) {
result.resolve(updatedItem);
}).fail(function () {
result.resolve(lastPrevItem);
});
return result.promise();
},
它现在正在使用上面的代码,朋友。但如果有的话,我需要改进我的代码,请告诉我。