-
Notifications
You must be signed in to change notification settings - Fork 52
/
directive.js
95 lines (81 loc) · 2.69 KB
/
directive.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'use strict'
angular.module('objectTable').directive('objectTable', ['$compile','$interpolate',function($compile, $interpolate) {
return {
restrict: 'A',
replace: true,
templateUrl: '/src/templates/common.html',
controller: 'objectTableCtrl',
controllerAs: 'ctrl',
transclude: true,
scope: {
data: '=',
display: '=?',
resize: '=?',
paging: '=?',
fromUrl: '@',
//search:"@?",
//headers:"@",
//fields:"@",
sortingType: '@?sorting',
editable: '&?',
select: '@?',
selectedModel: '=?',
dragColumns: '=?',
//events
onEdit: '&?',
onDrag: '&?',
},
compile: function(tElement, tAttributes) {
//collect filters
var rowFilter = '',
pagingFilter = '';
// additional user filters
if (!!tAttributes.addFilter) {
rowFilter += tAttributes.addFilter;
}
//If SORTING allowed
if (tAttributes.sorting !== 'false') {
rowFilter += '| orderBy:sortingArray';
}
// add 'allow-drag' attribute to header is just cistom tbody present
if (tAttributes.dragColumns) {
tElement.find('th').attr('allow-drag','');
}
//If SEARCH allowed
if (tAttributes.search === 'separate') {
tAttributes.fields.split(',').forEach(function(item, index) {
rowFilter += '| filter:{\'' + item.trim() + '\':columnSearch[\'' + item + '\']}';
});
} else if (typeof(tAttributes.search) === 'undefined' || tAttributes.search === 'true') {
rowFilter += '| filter:globalSearch';
}
//pagingFilter = rowFilter;
pagingFilter += ' | offset: currentPage:display |limitTo: display';
tElement[0].querySelector('#rowTr').setAttribute('ng-repeat','item in $parent.$filtered = (data' + rowFilter + ')' + pagingFilter);
//add paging
tElement.find('paging').attr('count','$filtered.length');
return function preLink(scope, element, attrs, ctrl, transclude) {
ctrl._init();
transclude(scope, function(clone, innerScope) {
scope.$owner = innerScope.$parent;
for (var key in clone) {
if (clone.hasOwnProperty(key)) {
switch (clone[key].tagName) {
case 'THEAD':
ctrl._addHeaderPattern(clone[key]);
break;
case 'TBODY':
scope.findBody = true;
ctrl._addRowPattern(clone[key],rowFilter,pagingFilter);
break;
case 'TFOOT':
ctrl._addFooterPattern(clone[key]);
break;
}
}
}
});
}; //[END transclude]
},
};
}]);