I have been working with AngularJS for months. Today, I need to create a directive that will help me add a fix header to a table. All the directives I've found were not good enough because of the way they deal with the columns size (I'm still opened for propositions).
We use an "old" function made with jQuery and I am trying to convert it to a directive. The goal is, to clone the table (or the header of the table) and deals with hide/show functions and its position to get a good result.
My problem: the header of my table is dynamic with generated columns:
<table>
<thead>
<tr>
<th></th> // true th elements, used for styling my table
<th></th>
<th class='text-center' ng-repeat="thing in things">
{{thing.label}}
</th>
</tr>
</thead>
<tbody>
// my tbody
</tbody>
</table>
I'm trying to get the <th>
element in my directive with something like that :
angular.forEach(elem.querySelectorAll('tr:first-child th'), function (thElem, i) {
console.log(thElem)
// do stuff here
}
});
But I just get the two first <th>
which are the "true" elements in my code. All others, generated by the ng-repeat are ignored. Or not injected in my directive.
I've looking around the transclude attribute but I could not find anything that works. Can you help me with some precision?
EDIT : Here is the beginning of my directive:
myApp.directive('fixMe', function ($window) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
angular.forEach(element.querySelectorAll('th'), function (thElem, i) {
console.log(thElem);
var columnWidth = thElem.offsetWidth;
thElem.style.width = columnWidth + 'px';
});
}
};
})