@@ -83,14 +83,17 @@ $.widget( "mobile.table", $.mobile.table, {
83
83
84
84
// create the hide/show toggles
85
85
this . headers . not ( "td" ) . each ( function ( ) {
86
- var header = $ ( this ) ,
86
+ var input ,
87
+ header = $ ( this ) ,
87
88
priority = $ . mobile . getAttribute ( this , "priority" ) ,
88
89
cells = header . add ( header . jqmData ( "cells" ) ) ;
89
90
90
91
if ( priority ) {
91
92
cells . addClass ( opts . classes . priorityPrefix + priority ) ;
92
93
93
- ( keep ? inputs . eq ( checkboxIndex ++ ) :
94
+ // Make sure the (new?) checkbox is associated with its header via .jqmData() and
95
+ // that, vice versa, the header is also associated with the checkbox
96
+ input = ( keep ? inputs . eq ( checkboxIndex ++ ) :
94
97
$ ( "<label><input type='checkbox' checked />" +
95
98
( header . children ( "abbr" ) . first ( ) . attr ( "title" ) ||
96
99
header . text ( ) ) +
@@ -100,7 +103,13 @@ $.widget( "mobile.table", $.mobile.table, {
100
103
. checkboxradio ( {
101
104
theme : opts . columnPopupTheme
102
105
} ) )
103
- . jqmData ( "cells" , cells ) ;
106
+
107
+ // Associate the header with the checkbox
108
+ . jqmData ( "header" , header )
109
+ . jqmData ( "cells" , cells ) ;
110
+
111
+ // Associate the checkbox with the header
112
+ header . jqmData ( "input" , input ) ;
104
113
}
105
114
} ) ;
106
115
@@ -174,18 +183,48 @@ $.widget( "mobile.table", $.mobile.table, {
174
183
} ,
175
184
176
185
_refresh : function ( create ) {
186
+ var headers , hiddenColumns , index ;
187
+
188
+ // Calling _super() here updates this.headers
177
189
this . _super ( create ) ;
178
190
179
191
if ( ! create && this . options . mode === "columntoggle" ) {
192
+ headers = this . headers ;
193
+ hiddenColumns = [ ] ;
194
+
195
+ // Find the index of the column header associated with each old checkbox among the
196
+ // post-refresh headers and, if the header is still there, make sure the corresponding
197
+ // column will be hidden if the pre-refresh checkbox indicates that the column is
198
+ // hidden by recording its index in the array of hidden columns.
199
+ this . _menu . find ( "input" ) . each ( function ( ) {
200
+ var input = $ ( this ) ,
201
+ header = input . jqmData ( "header" ) ,
202
+ index = headers . index ( header [ 0 ] ) ;
203
+
204
+ if ( index > - 1 && ! input . prop ( "checked" ) ) {
205
+
206
+ // The column header associated with /this/ checkbox is still present in the
207
+ // post-refresh table and the checkbox is not checked, so the column associated
208
+ // with this column header is currently hidden. Let's record that.
209
+ hiddenColumns . push ( index ) ;
210
+ }
211
+ } ) ;
212
+
180
213
// columns not being replaced must be cleared from input toggle-locks
181
214
this . _unlockCells ( this . element . find ( ".ui-table-cell-hidden, " +
182
215
".ui-table-cell-visible" ) ) ;
183
216
184
217
// update columntoggles and cells
185
218
this . _addToggles ( this . _menu , create ) ;
186
219
187
- // check/uncheck
188
- this . _setToggleState ( ) ;
220
+ // At this point all columns are visible, so uncheck the checkboxes that correspond to
221
+ // those columns we've found to be hidden
222
+ for ( index = hiddenColumns . length - 1 ; index > - 1 ; index -- ) {
223
+ headers . eq ( hiddenColumns [ index ] ) . jqmData ( "input" )
224
+ . prop ( "checked" , false )
225
+ . checkboxradio ( "refresh" )
226
+ . trigger ( "change" ) ;
227
+ }
189
228
}
190
229
} ,
191
230
0 commit comments