|
282 | 282 | }); |
283 | 283 | } |
284 | 284 | }]) |
| 285 | + .directive('gridItem', ['$compile', function ($compile) { |
| 286 | + return { |
| 287 | + restrict: 'EA', |
| 288 | + terminal:true, |
| 289 | + scope: false, |
| 290 | + link: function ($scope, element, attrs, ctrl, transclude) { |
| 291 | + if ($scope.serverPagination) { |
| 292 | + element.attr('ng-repeat', "item in filtered"); |
| 293 | + } else { |
| 294 | + element.attr('ng-repeat', "item in filtered | startFrom:(paginationOptions.currentPage-1)*paginationOptions.itemsPerPage | limitTo:paginationOptions.itemsPerPage track by $index"); |
| 295 | + } |
| 296 | + element.removeAttr('grid-item'); |
| 297 | + var html = element[0].outerHTML; |
| 298 | + element.replaceWith($compile(html)($scope)); |
| 299 | + } |
| 300 | + } |
| 301 | + }]) |
285 | 302 | .directive('gridData', ['$compile', '$animate', function ($compile) { |
286 | 303 | return { |
287 | 304 | restrict: 'EA', |
|
290 | 307 | scope: true, |
291 | 308 | controller: 'gridController', |
292 | 309 | link: function ($scope, $element, attrs) { |
293 | | - var sorting = [], |
294 | | - filters = [], |
295 | | - rows = [], |
| 310 | + var filters = [], |
296 | 311 | directiveElement = $element.parent(), |
297 | 312 | gridId = attrs.id, |
298 | 313 | serverPagination = attrs.serverPagination === 'true'; |
| 314 | + $scope.serverPagination = serverPagination; |
299 | 315 |
|
300 | 316 |
|
301 | 317 | angular.forEach(angular.element(directiveElement[0].querySelectorAll('[sortable]')), function (sortable) { |
302 | 318 | var element = angular.element(sortable), |
303 | 319 | predicate = element.attr('sortable'); |
304 | | - sorting.push(element); |
305 | 320 | element.attr('ng-class', "{'sort-ascent' : sortOptions.predicate ==='" + |
306 | 321 | predicate + "' && sortOptions.direction === 'asc', 'sort-descent' : sortOptions.predicate === '" + |
307 | 322 | predicate + "' && sortOptions.direction === 'desc'}"); |
|
348 | 363 | }); |
349 | 364 | }); |
350 | 365 |
|
351 | | - angular.forEach(angular.element(directiveElement[0].querySelectorAll('[grid-item]')), function (row) { |
352 | | - var element = angular.element(row); |
353 | | - rows.push(element); |
354 | | - if (serverPagination) { |
355 | | - element.attr('ng-repeat', "item in filtered"); |
356 | | - } else { |
357 | | - element.attr('ng-repeat', "item in filtered | startFrom:(paginationOptions.currentPage-1)*paginationOptions.itemsPerPage | limitTo:paginationOptions.itemsPerPage track by $index"); |
358 | | - } |
359 | | - $compile(element)($scope); |
360 | | - }); |
361 | | - |
362 | | - $scope.sorting = sorting; |
363 | | - $scope.rows = rows; |
364 | 366 | $scope.filters = filters; |
365 | 367 | } |
366 | 368 | } |
|
0 commit comments