@@ -33,24 +33,45 @@ var SelectorTable = {
3333 }
3434 }
3535 isVerticalRow = true ;
36-
36+
3737 } else if ( $headerRow . find ( "th" ) . length ) {
3838 $headerRow = $headerRow . find ( "th" ) ;
3939 } else if ( $headerRow . find ( "td" ) . length ) {
4040 $headerRow = $headerRow . find ( "td" ) ;
4141 }
4242
43- $headerRow . each ( function ( i ) {
44- var header = $ ( this ) . text ( ) . trim ( ) ;
43+ $headerRow . each ( function ( i , value ) {
44+ var header = $ ( value ) . text ( ) . trim ( ) ;
4545 columns [ header ] = {
4646 index : i + 1 ,
4747 isVerticalHeader : isVerticalRow
4848 } ;
49- } ) ;
49+ } . bind ( this ) ) ;
50+
51+ this . addMissingColumns ( $headerRow ) ;
5052 }
5153 return columns ;
5254 } ,
5355
56+ addMissingColumns ( headerRow ) {
57+ headerRow . each ( function ( i , value ) {
58+ if ( this . tableAddMissingColumns ) {
59+ var header = $ ( value ) . text ( ) . trim ( ) ;
60+ var column = $ . grep ( this . columns , function ( h ) {
61+ return h . name === header ;
62+ } ) ;
63+
64+ if ( column . length !== 1 ) {
65+ this . columns . push ( {
66+ header : header ,
67+ name : header ,
68+ extract : true
69+ } ) ;
70+ }
71+ }
72+ } . bind ( this ) ) ;
73+ } ,
74+
5475 getVerticalDataCells : function ( table , dataSelector ) {
5576 var selectors = $ ( table ) . find ( dataSelector ) ,
5677 isRow = selectors [ 0 ] . nodeName === "TR" ,
@@ -70,13 +91,14 @@ var SelectorTable = {
7091 var index = ( dataCell . cellIndex - 1 | dataCell . rowIndex ) ;
7192 var headerCellName = $ ( dataCell ) . closest ( 'tr' ) . find ( "th:first-child" ) . text ( ) . trim ( ) ;
7293 var dataCellvalue = $ ( dataCell ) . text ( ) . trim ( ) ;
94+
7395 var extractData = $ . grep ( this . columns , function ( h ) {
7496 return h . name === headerCellName && h . extract ;
7597 } ) . length == 1 ;
7698
7799 if ( extractData ) {
78100 result [ index ] [ headerCellName ] = dataCellvalue ;
79- }
101+ }
80102 }
81103 } . bind ( this ) ) ;
82104 }
@@ -98,27 +120,28 @@ var SelectorTable = {
98120 headerCellCount = objKeys . length ,
99121 isVerticalHeader = headerCellCount && headerCells [ Object . keys ( headerCells ) [ 0 ] ] . isVerticalHeader ;
100122
101- if ( isVerticalHeader ) {
102- var results = this . getVerticalDataCells ( table , dataSelector ) ;
103- result . push . apply ( result , results ) ;
104- } else {
105- $ ( table ) . find ( dataSelector ) . each ( function ( i , dataCell ) {
106- var data = { } ;
107- this . columns . forEach ( function ( headerCell ) {
108- if ( headerCell . extract === true ) {
109- if ( headerCells [ headerCell . header ] === undefined ) {
110- data [ headerCell . name ] = null ;
111- }
112- else {
113- var header = headerCells [ headerCell . header ] ;
114- var rowText = $ ( dataCell ) . find ( ">:nth-child(" + header . index + ")" ) . text ( ) . trim ( ) ;
115- data [ headerCell . name ] = rowText ;
116- }
123+ if ( isVerticalHeader ) {
124+ var results = this . getVerticalDataCells ( table , dataSelector ) ;
125+ result . push . apply ( result , results ) ;
126+ } else {
127+ $ ( table ) . find ( dataSelector ) . each ( function ( i , dataCell ) {
128+ var data = { } ;
129+
130+ this . columns . forEach ( function ( headerCell ) {
131+ if ( headerCell . extract === true ) {
132+ if ( headerCells [ headerCell . header ] === undefined ) {
133+ data [ headerCell . name ] = null ;
117134 }
118- } ) ;
119- result . push ( data ) ;
120- } . bind ( this ) ) ;
121- }
135+ else {
136+ var header = headerCells [ headerCell . header ] ;
137+ var rowText = $ ( dataCell ) . find ( ">:nth-child(" + header . index + ")" ) . text ( ) . trim ( ) ;
138+ data [ headerCell . name ] = rowText ;
139+ }
140+ }
141+ } ) ;
142+ result . push ( data ) ;
143+ } . bind ( this ) ) ;
144+ }
122145 } . bind ( this ) ) ;
123146
124147 dfd . resolve ( result ) ;
@@ -137,7 +160,7 @@ var SelectorTable = {
137160 } ,
138161
139162 getFeatures : function ( ) {
140- return [ 'multiple' , 'columns' , 'delay' , 'tableDataRowSelector' , 'tableHeaderRowSelector' ]
163+ return [ 'multiple' , 'columns' , 'delay' , 'tableDataRowSelector' , 'tableHeaderRowSelector' , 'tableAddMissingColumns' ]
141164 } ,
142165
143166 getItemCSSSelector : function ( ) {
0 commit comments