Skip to content

Commit c8fba9a

Browse files
committed
fix(directive): handle responsive-dynamic on other columns
1 parent 22fa6ef commit c8fba9a

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/directive.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ function getHeaders(element) {
66

77
function updateTitle(td, th) {
88
var title = th && th.textContent;
9-
if (title && !td.getAttributeNode('data-title')) {
9+
if (title && (td.getAttributeNode('data-title-override') || !td.getAttributeNode('data-title'))) {
1010
td.setAttribute('data-title', title);
11+
td.setAttribute('data-title-override', title);
1112
}
1213
}
1314

@@ -77,9 +78,10 @@ function wtResponsiveDynamic() {
7778
restrict: 'A',
7879
require: '^^wtResponsiveTable',
7980
link: function (scope, element, attrs, tableCtrl) {
80-
var td = element[0];
81-
var th = tableCtrl.getHeader(td);
82-
updateTitle(td, th);
81+
Array.prototype.forEach.call(element[0].parentElement.querySelectorAll("td"), function (td) {
82+
var th = tableCtrl.getHeader(td);
83+
updateTitle(td, th);
84+
});
8385
}
8486
};
8587
}

tests/directive.spec.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,8 @@ describe('directive', function () {
331331
expect(styles.paddingLeft).toBe('50%');
332332
});
333333

334-
describe('wt-responsive-column', function () {
335-
it('supports ng-if applied on TD', function () {
334+
describe('responsive-dynamic', function () {
335+
it('supports ng-if applied on all TDs', function () {
336336
var markup = [
337337
'<table wt-responsive-table>',
338338
' <thead>',
@@ -360,5 +360,37 @@ describe('directive', function () {
360360
expect(els.eq(0).attr('data-title')).toBe('column');
361361
});
362362

363+
it('supports ng-if applied on some TDs', function () {
364+
var markup = [
365+
'<table wt-responsive-table>',
366+
' <thead>',
367+
' <tr>',
368+
' <th>column</th>',
369+
' <th>simple</th>',
370+
' </tr>',
371+
' </thead>',
372+
' <tbody>',
373+
' <tr>',
374+
' <td ng-if="!condition" responsive-dynamic>tom</td>',
375+
' <td ng-if="condition" responsive-dynamic>jerry</td>',
376+
' <td>simple</td>',
377+
' </tr>',
378+
' </tbody>',
379+
'</table>'
380+
].join('');
381+
var element = angular.element(markup);
382+
var scope = $rootScope.$new();
383+
scope.condition = true;
384+
385+
$compile(element)(scope);
386+
scope.$digest();
387+
388+
var els = element.find('tbody tr:first td');
389+
expect(els.eq(0).text()).toBe('jerry');
390+
expect(els.eq(0).attr('data-title')).toBe('column');
391+
expect(els.eq(1).text()).toBe('simple');
392+
expect(els.eq(1).attr('data-title')).toBe('simple');
393+
});
394+
363395
});
364396
});

0 commit comments

Comments
 (0)