AngularJs + Datatables 显示表格

1、需要加入的资源文件


2、在模块中注入datatbles依赖

APP_NAME = "showCaseApp";
var showCaseApp = angular.module(APP_NAME, ["ui.router","datatables","ngResource"]);

3、HTML文件

4、JavaScript文件


angular.module(APP_NAME).controller('WithPromiseCtrl', 
        ["$scope", "$rootScope","$http", "$q","utils","DTOptionsBuilder","DTColumnBuilder","$resource",
        function ($scope,$rootScope,$http,$q,utils,DTOptionsBuilder, DTColumnBuilder,$resource) {
   
            $scope.rang = [
                           {value:3,name:'最近3天'},
                           {value:7,name:'最近7天'},
                           {value:30,name:'最近一个月'},
                           {value:0,name:'全部'}
                ];
            
            var vm = this;
            vm.dtOptions = DTOptionsBuilder.fromFnPromise(function() {
                var defer = $q.defer();
                $http.get("/" + utils.getContextPath() + "/board/getActivityList?range=" + 3 + "&module=" + $rootScope.nodeText)
                    .then(function(result) {
                        defer.resolve(result.data.data);
                    });
                return defer.promise;
            }).withPaginationType('simple_numbers');

            vm.dtColumns = [
                DTColumnBuilder.newColumn('actionTime').withTitle('活动时间'),
                DTColumnBuilder.newColumn('dept4').withTitle('四级部门'),
                DTColumnBuilder.newColumn('userId').withTitle('姓名'),
                DTColumnBuilder.newColumn('subModule').withTitle('活动类型'),
                DTColumnBuilder.newColumn('actionDesc').withTitle('活动描述'),
                DTColumnBuilder.newColumn('offering').withTitle('版本号')
            ];
            
            vm.dtInstance = {};
            
            $scope.change = function(){
               
                vm.dtInstance.changeData(function() {
//                  return $resource(
//                          "/" + utils.getContextPath() + "/board/getActivityList?range=" + $scope.selectedRang.value + "&module=" + $rootScope.nodeText)
//                          .get().$promise;
                    var defer = $q.defer();
                    $http.get("/" + utils.getContextPath() + "/board/getActivityList?range=" + $scope.selectedRang.value + "&module=" + $rootScope.nodeText) 
                        .then(function(result) {
                            defer.resolve(result.data.data);
                        });
                    return defer.promise;
                });
                                        
            }
            
            
}])

你可能感兴趣的:(AngularJs + Datatables 显示表格)