代码之家  ›  专栏  ›  技术社区  ›  simple user

如何在添加数据后自动刷新用户界面网格

  •  0
  • simple user  · 技术社区  · 6 年前

    我有一个角度的UI网格,我想在添加数据后重新加载它。请让我知道我需要补充什么?

    HTML文件

    <form class="form-main">
      <label>Category Name</label>
      <input type="text" id="txtCategory" ng-model="md_catname" />
      <button id="btnAdd" type="submit" class ="button-internal" ng-click="Add()">Add</button>    
      <div class="gridBigStyle" ui-grid="gridCategory" ui-grid-edit ui-grid-pagination>            
    </form>
    

    控制器文件

    var myApp = angular.module('appHome');
    myApp.controller("ctrlCategory", ['$scope', 'MetadataOrgFactory', 'CommonFunctionFactory', function ($scope, MetadataOrgFactory, CommonFunctionFactory) {
        $scope.gridCategory = {
            data: 'categoryData',        
            columnDefs: [
                {
                    field: 'CategoryName', displayName: 'Name',                
                },           
            ]
        }
    
        //This is to retrieve existing categories from Database
        MetadataOrgFactory.getApiCall('getallcatgories', function (dataSuccess) {
            $scope.categoryData = dataSuccess;
        }, function (dataError) {
        });
    
        //Common Function being called to Add Category Name
        $scope.Add = function () {
            var objCategory = {
                'CategoryName': $scope.md_catname,            
            };
            CommonFunctionFactory.AddMasterData(objCategory, function (dataSuccess) {
            }, function (dataError) {
            });
        }
    }])
    

    通用函数文件

    var appService = angular.module('appHome');
    appService.factory('CommonFunctionFactory', ['MetadataOrgFactory', function (MetadataOrgFactory) {
        var dataFactory = {};
    
        //Adding Master Data to DB
        dataFactory.AddMasterData = function (objData) {
            MetadataOrgFactory.postApiCall(serviceFunc, objMasterData, function (dataSuccess) {
                alert("The request has been completed succesfully");
            }, function (dataError) {
        });
        };
    }])
    

    我想了解要放置什么代码,以便在数据加载到DB后,Angular UI网格自动刷新。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Priyanka Jethwa    6 年前

    获取更新数据的完整列表,作为成功更新的返回,并将数据馈送到网格,即$scope。网格选项。数据=最新数据;