Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Table Toggle/Reflow: added rebuild method
Browse files Browse the repository at this point in the history
  • Loading branch information
frequent committed Jul 23, 2013
1 parent 3fb928e commit 1f4c1fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
36 changes: 24 additions & 12 deletions js/widgets/table.columntoggle.js
Expand Up @@ -77,10 +77,13 @@ $.widget( "mobile.table", $.mobile.table, {
});
},

_addToggles: function( menu ) {
_addToggles: function( menu, keep ) {
var opts = this.options;

// allow update of menu on refresh (fixes #5880)
menu.empty();
if ( !keep ) {
menu.empty();
}

// create the hide/show toggles
this.headers.not( "td" ).each( function() {
Expand All @@ -92,13 +95,15 @@ $.widget( "mobile.table", $.mobile.table, {
if( priority ) {
$cells.addClass( opts.classes.priorityPrefix + priority );

$("<label><input type='checkbox' checked />" + $this.text() + "</label>" )
.appendTo( menu )
.children( 0 )
.data( "cells", $cells )
.checkboxradio( {
theme: opts.columnPopupTheme
});
if ( !keep ) {
$("<label><input type='checkbox' checked />" + $this.text() + "</label>" )
.appendTo( menu )
.children( 0 )
.data( "cells", $cells )
.checkboxradio( {
theme: opts.columnPopupTheme
});
}
}

});
Expand Down Expand Up @@ -146,8 +151,8 @@ $.widget( "mobile.table", $.mobile.table, {
$popup = $( "<div data-" + ns + "role='popup' data-" + ns + "role='fieldcontain' class='" + opts.classes.popup + "' id='" + id + "'></div>" );
$menu = $( "<fieldset data-" + ns + "role='controlgroup'></fieldset>" );

// set extension here
this._addToggles( $menu );
// set extension here, send "false" to trigger build/rebuild
this._addToggles( $menu, false );

$menu.appendTo( $popup );

Expand All @@ -160,6 +165,13 @@ $.widget( "mobile.table", $.mobile.table, {
return $menu;
},

rebuild: function() {
// NOTE: rebuild passes "false", while refresh passes "undefined"
// both refresh the table, but inside addToggles, !false will be true,
// so a rebuild call can be indentified
this.refresh( false );
},

refresh: function( create ) {
this._super( create );

Expand All @@ -168,7 +180,7 @@ $.widget( "mobile.table", $.mobile.table, {
this._unlockCells( this.allHeaders );

// update columntoggles and $cells
this._addToggles( this._menu );
this._addToggles( this._menu, create );

// check/uncheck
this._setToggleState();
Expand Down
4 changes: 4 additions & 0 deletions js/widgets/table.reflow.js
Expand Up @@ -35,6 +35,10 @@ $.widget( "mobile.table", $.mobile.table, {
}
},

rebuild: function() {
this.refresh( false );
},

refresh: function( create ) {
this._super( create );
if ( !create && this.options.mode === "reflow" ) {
Expand Down

0 comments on commit 1f4c1fd

Please sign in to comment.