-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable_directive.js
33 lines (32 loc) · 959 Bytes
/
table_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
/**
* theaders er et objekt med kolonnenavn og -bredder
* tbody trenger større fleksibiltet og bør nok derfor transcluderes inn
*/
angular.module("directive.scrollable.table", []).directive("scrollableTable", function() {
"use strict";
return {
restrict: 'EA',
scope: {
theaders:'=',
tfooter:'=',
},
link: function(scope, element, attrs, ctrl, transclude) {
element.find('tbody').replaceWith(transclude());
var tdArr = element.find('tbody').find('tr').eq(0).children();
angular.forEach(scope.theaders, function(thObj, i){
if (i+1 < tdArr.length) {
angular.element(tdArr[i]).css('width', thObj.width);
} else {
angular.element(tdArr[i]).css('width', 'calc('+thObj.width+' - 17px)');
}
});
},
templateUrl: 'table_directive.tpl.html',
replace: true,
transclude: true
/*{
header: '?thead',
body: 'tbody'
}*/
};
});