Browse Source

fixed basic display table

tags/0.1.0
Robin Thoni 9 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
                 },
13
                 templateUrl: "/luticate/lubasictable.html",
13
                 templateUrl: "/luticate/lubasictable.html",
14
                 link: function ($scope, element, attrs) {
14
                 link: function ($scope, element, attrs) {
15
-                    $scope.page = 0;
16
-                    $scope.perPage = 15;
17
                     $scope.items = [];
15
                     $scope.items = [];
18
                     $scope.pages = [];
16
                     $scope.pages = [];
19
 
17
 
20
                     $scope.tableOptions = $scope.options();
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
                     if ($scope.tableOptions.checkedItems == null) {
25
                     if ($scope.tableOptions.checkedItems == null) {
22
                         $scope.tableOptions.checkedItems = [];
26
                         $scope.tableOptions.checkedItems = [];
23
                     }
27
                     }
55
                             id: "promiseLoadItems",
59
                             id: "promiseLoadItems",
56
                             groups: ['itemList']
60
                             groups: ['itemList']
57
                         };
61
                         };
58
-                        $scope.tableOptions.getLoadPagePromise(page, $scope.perPage, promiseLoadItems)
62
+                        $scope.tableOptions.getLoadPagePromise(page, $scope.tableOptions.perPage, promiseLoadItems)
59
                             .then(function (items) {
63
                             .then(function (items) {
60
-                                $scope.page = page;
64
+                                $scope.tableOptions.page = page;
61
                                 $scope.items = items;
65
                                 $scope.items = items;
62
                                 $scope.pages = [];
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
                                 for (var i = start; i < end; ++i) {
70
                                 for (var i = start; i < end; ++i) {
66
                                     $scope.pages.push(i);
71
                                     $scope.pages.push(i);
67
                                 }
72
                                 }
104
                         $scope.tableOptions.onItemClicked(item, $scope);
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
 '</table>' +
140
 '</table>' +
136
 
141
 
137
 '<div class="col-sm-12 text-center">' +
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
 '</div>' +
144
 '</div>' +
140
 '    </div>');
145
 '    </div>');
141
 }]);
146
 }]);

Loading…
Cancel
Save