@@ -83,14 +83,17 @@ $.widget( "mobile.table", $.mobile.table, {
8383
8484 // create the hide/show toggles
8585 this . headers . not ( "td" ) . each ( function ( ) {
86- var header = $ ( this ) ,
86+ var input ,
87+ header = $ ( this ) ,
8788 priority = $ . mobile . getAttribute ( this , "priority" ) ,
8889 cells = header . add ( header . jqmData ( "cells" ) ) ;
8990
9091 if ( priority ) {
9192 cells . addClass ( opts . classes . priorityPrefix + priority ) ;
9293
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 ++ ) :
9497 $ ( "<label><input type='checkbox' checked />" +
9598 ( header . children ( "abbr" ) . first ( ) . attr ( "title" ) ||
9699 header . text ( ) ) +
@@ -100,7 +103,13 @@ $.widget( "mobile.table", $.mobile.table, {
100103 . checkboxradio ( {
101104 theme : opts . columnPopupTheme
102105 } ) )
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 ) ;
104113 }
105114 } ) ;
106115
@@ -174,18 +183,48 @@ $.widget( "mobile.table", $.mobile.table, {
174183 } ,
175184
176185 _refresh : function ( create ) {
186+ var headers , hiddenColumns , index ;
187+
188+ // Calling _super() here updates this.headers
177189 this . _super ( create ) ;
178190
179191 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+
180213 // columns not being replaced must be cleared from input toggle-locks
181214 this . _unlockCells ( this . element . find ( ".ui-table-cell-hidden, " +
182215 ".ui-table-cell-visible" ) ) ;
183216
184217 // update columntoggles and cells
185218 this . _addToggles ( this . _menu , create ) ;
186219
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+ }
189228 }
190229 } ,
191230
0 commit comments