创建或更新行后,Kendo-ui网格不会刷新

时间:2016-02-07 05:32:29

标签: angularjs kendo-ui kendo-grid angular-kendo

我的剑道网格在编辑或创建新行后不会刷新。我已经为CRUD操作调用了angularJS服务。

这是控制器

app.controller("roadInventoryCtrl", function ($scope, services) {
$scope.gridOptions = {
    columns: [
        {
            field: "RoadCode",
            title: "Road Code",
            width: "",
            attributes: { class: "ob-right" }
        },
        {
            field: "Remarks",
            filterable: false
        },
        {
            command: [
                {
                    name: "edit",
                    template: "<a data-toggle='tooltip' data-placement='left' title='edit' class='k-grid-edit k-grid-update red-tooltip'  style='width: 26px; height: 26px; vertical-align: middle; text-align: center; cursor:pointer'><span style='margin: 4px;' class='glyphicon glyphicon-edit'></span></a>",
                    text: " "

                },
                {
                    name: "destroy",
                    template: "<a if-role-permission=\"['PERMISSION_WORKFLOW_DEFINITION_DELETE']\" class='k-grid-delete'  style='width: 26px; height: 26px; vertical-align: middle; text-align: center; cursor:pointer' ><span style='margin: 4px;' class='glyphicon glyphicon-remove-circle target' title='delete'></span></a>",
                    text: " "
                }
            ],
        }
    ],

    editable: 'inline',
    toolbar: ["create"],
    pageable: true,

    dataSource: {
        pageSize: 25,
        transport: {
            read: function(e) {
                services.getRoadInventroy()
                    .then(function success(response) {
                        e.success(response.data);
                    }, function error(response) {
                        alert('something went wrong');
                        console.log(response);
                    });
            },
            update: function(e) {
                services.updateRoadInventory(e)
                    .then(function success(response) {
                        e.success(response.data);
                    }, function error(response) {
                        console.log(response);
                    });
            },

            destroy: function(e) {
                services.destroyRoadInventory()
                    .then(function success(response) {
                            e.success(response.data);
                        }, function error(response) {
                            console.log(response);
                        }
                    );

            },
            create: function(e) {
                services.createRoadInventory(e)
                    .then(function success(response) {
                            console.log(response);
                        },function error(response) {
                            console.log(response);
                        }
                    );
            }
        },
        schema: {
            model: {
                id: "RoadCode",
                fields: {
                    RoadCode: {
                        editable: false
                    }

                }
            }
        }
    },
    sortable: true,
    selectable: "row",

    filterable: {
        extra: false,
        operators: {
        string: {
            startswith: "Starts with",
            contains:"Contains"

         },
         number: {
         }
       }
    }


    }



});

服务是

app.service('services', ['$http', function ($http) {
var result;
this.getRoadInventroy = function () {
    result = $http.get("/api/InventoryService").success(function (data) {
        result = (data);
    }).error(function () {
        alert("Not hiting the Api Controller");
    });

    return result;
};

this.createRoadInventory = function (e) {
    //alert(JSON.stringify(e));
    //alert(e.data);
    $http.post("/api/InventoryService",e.data).success(function () {
    }).error(function() {
        alert("Not Hitting the POST of API but hitting the services");
    });
};
this.destroyRoadInventory = function () {

};
this.updateRoadInventory = function (e) {
    $http.put("/api/InventoryService", e.data).success(function () {
    }).error(function (){
        alert("Not Hitting the put of API but hitting the services");
    });
};



}]);

我已将它发布在剑道论坛上,但没有得到适当的答案。

1 个答案:

答案 0 :(得分:0)

将结果放入var并返回。

        this.updateRoadInventory = function(e) {
        update = $http.put(rootUrl + "InventoryService", e.data).success(function() {
        }).error(function() {
            alert("Not Hitting the put of API but hitting the services");
        });
        return update;
    };