@@ -14,7 +14,7 @@ function updateTitle(td, th) {
1414function colspan ( td ) {
1515 var colspan = td . getAttributeNode ( 'colspan' ) ;
1616 return colspan ? parseInt ( colspan . value ) : 1 ;
17- }
17+ }
1818
1919function wtResponsiveTable ( ) {
2020 return {
@@ -25,7 +25,7 @@ function wtResponsiveTable() {
2525 var headers = getHeaders ( $element [ 0 ] ) ;
2626 if ( headers . length ) {
2727 var row = td . parentElement ;
28- var headerIndex = 0 ;
28+ var headerIndex = 0 ;
2929 var found = Array . prototype . some . call ( row . querySelectorAll ( 'td' ) , function ( value , index ) {
3030 if ( value === td ) {
3131 return true ;
@@ -40,21 +40,33 @@ function wtResponsiveTable() {
4040 }
4141 } ,
4242 compile : function ( element , attrs ) {
43- attrs . $addClass ( 'responsive' ) ;
44- var headers = getHeaders ( element [ 0 ] ) ;
45- if ( headers . length ) {
46- var rows = element [ 0 ] . querySelectorAll ( 'tbody > tr' ) ;
47- Array . prototype . forEach . call ( rows , function ( row ) {
48- var headerIndex = 0 ;
49- Array . prototype . forEach . call ( row . querySelectorAll ( 'td' ) , function ( value , index ) {
50- if ( ! value . getAttributeNode ( 'responsive-dynamic' ) ) {
51- var th = value . parentElement . querySelector ( 'th' ) || headers . item ( headerIndex ) ;
52- updateTitle ( value , th ) ;
53- }
43+ function apply ( ) {
44+ var headers = getHeaders ( element [ 0 ] ) ;
45+ if ( headers . length ) {
46+ var rows = element [ 0 ] . querySelectorAll ( 'tbody > tr' ) ;
47+ Array . prototype . forEach . call ( rows , function ( row ) {
48+ var headerIndex = 0 ;
49+ Array . prototype . forEach . call ( row . querySelectorAll ( 'td' ) , function ( value , index ) {
50+ if ( ! value . getAttributeNode ( 'responsive-dynamic' ) ) {
51+ var th = value . parentElement . querySelector ( 'th' ) || headers . item ( headerIndex ) ;
52+ updateTitle ( value , th ) ;
53+ }
5454
55- headerIndex += colspan ( value ) ;
55+ headerIndex += colspan ( value ) ;
56+ } ) ;
5657 } ) ;
57- } ) ;
58+ }
59+ }
60+
61+ attrs . $addClass ( 'responsive' ) ;
62+ if ( Array . prototype . some . call ( element . find ( 'th' ) , function ( it ) {
63+ return it . getAttributeNode ( 'ng-repeat' ) || it . getAttributeNode ( 'data-ng-repeat' )
64+ } ) ) {
65+ setTimeout ( function ( ) {
66+ apply ( ) ;
67+ } , 0 ) ;
68+ } else {
69+ apply ( ) ;
5870 }
5971 }
6072 } ;
@@ -66,8 +78,8 @@ function wtResponsiveDynamic() {
6678 require : '^^wtResponsiveTable' ,
6779 link : function ( scope , element , attrs , tableCtrl ) {
6880 var td = element [ 0 ] ;
69- var th = tableCtrl . getHeader ( td ) ;
81+ var th = tableCtrl . getHeader ( td ) ;
7082 updateTitle ( td , th ) ;
7183 }
7284 } ;
73- }
85+ }
0 commit comments