0

我从数据库更新网格值。并将值从 CS 页面传递到 JSgrid。Delete,Edit 与 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" },
        ]
    });

一旦触发搜索按钮,我想用 jsgrid 更新 <%=gridData%> 。

4

1 回答 1

1
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();
                },

它现在可以使用上面的代码,朋友们。但是如果有什么需要改进的,请告诉我。

于 2017-06-19T11:58:27.357 回答