Browse Source

fixed basic display table

tags/0.1.0
Robin Thoni 8 years ago
parent
commit
6b7f13b466
1 changed files with 13 additions and 8 deletions
  1. 13
    8
      src/lubasictable.js

+ 13
- 8
src/lubasictable.js View File

@@ -12,12 +12,16 @@ angular.module('luticateUtils')
12 12
                 },
13 13
                 templateUrl: "/luticate/lubasictable.html",
14 14
                 link: function ($scope, element, attrs) {
15
-                    $scope.page = 0;
16
-                    $scope.perPage = 15;
17 15
                     $scope.items = [];
18 16
                     $scope.pages = [];
19 17
 
20 18
                     $scope.tableOptions = $scope.options();
19
+                    if ($scope.tableOptions.page == null) {
20
+                        $scope.tableOptions.page = 0;
21
+                    }
22
+                    if ($scope.tableOptions.perPage == null) {
23
+                        $scope.tableOptions.perPage = 15;
24
+                    }
21 25
                     if ($scope.tableOptions.checkedItems == null) {
22 26
                         $scope.tableOptions.checkedItems = [];
23 27
                     }
@@ -55,13 +59,14 @@ angular.module('luticateUtils')
55 59
                             id: "promiseLoadItems",
56 60
                             groups: ['itemList']
57 61
                         };
58
-                        $scope.tableOptions.getLoadPagePromise(page, $scope.perPage, promiseLoadItems)
62
+                        $scope.tableOptions.getLoadPagePromise(page, $scope.tableOptions.perPage, promiseLoadItems)
59 63
                             .then(function (items) {
60
-                                $scope.page = page;
64
+                                $scope.tableOptions.page = page;
61 65
                                 $scope.items = items;
62 66
                                 $scope.pages = [];
63
-                                var start = Math.max(0, $scope.page - 5);
64
-                                var end = Math.min(start + 10, (items.Count / $scope.perPage) + (items.Count % $scope.perPage == 0 ? -1 : 0));
67
+                                var start = Math.max(0, $scope.tableOptions.page - 5);
68
+                                var end = Math.min(start + 10, (items.Count / $scope.tableOptions.perPage)
69
+                                    + (items.Count % $scope.tableOptions.perPage == 0 ? -1 : 0));
65 70
                                 for (var i = start; i < end; ++i) {
66 71
                                     $scope.pages.push(i);
67 72
                                 }
@@ -104,7 +109,7 @@ angular.module('luticateUtils')
104 109
                         $scope.tableOptions.onItemClicked(item, $scope);
105 110
                     };
106 111
 
107
-                    $scope.loadPage($scope.page);
112
+                    $scope.loadPage($scope.tableOptions.page);
108 113
                 }
109 114
             };
110 115
         }
@@ -135,7 +140,7 @@ angular.module('luticateUtils').run(['$templateCache', function($templateCache)
135 140
 '</table>' +
136 141
 
137 142
 '<div class="col-sm-12 text-center">' +
138
-'    <a class="{{ p == page ? \'pagination-current\' : \'pagination-not-current\'}}" href="" ng-repeat="p in pages" ng-click="loadPage(p)">{{ p + 1 }}&nbsp;</a>' +
143
+'    <a class="{{ p == tableOptions.page ? \'pagination-current\' : \'pagination-not-current\'}}" href="" ng-repeat="p in pages" ng-click="loadPage(p)">{{ p + 1 }}&nbsp;</a>' +
139 144
 '</div>' +
140 145
 '    </div>');
141 146
 }]);

Loading…
Cancel
Save