Core: Add widget from class before adding options

This commit is contained in:
Rob Garrison 2015-10-29 23:56:02 -05:00
parent e284dd6090
commit b8880d65f9

View File

@ -272,8 +272,10 @@
// fixate columns if the users supplies the fixedWidth option // fixate columns if the users supplies the fixedWidth option
// do this after theme has been applied // do this after theme has been applied
ts.fixColumnWidth( table ); ts.fixColumnWidth( table );
// add widgets from class name
ts.addWidgetFromClass( table );
// add widget options before parsing (e.g. grouping widget has parser settings) // add widget options before parsing (e.g. grouping widget has parser settings)
ts.applyWidgetOptions( table, c ); ts.applyWidgetOptions( table );
// try to auto detect column type, and store in tables config // try to auto detect column type, and store in tables config
ts.setupParsers( c ); ts.setupParsers( c );
// start total row count at zero // start total row count at zero
@ -1181,7 +1183,6 @@
c.$table.find( c.selectorRemove ).remove(); c.$table.find( c.selectorRemove ).remove();
// get position from the dom // get position from the dom
var tmp, indx, row, icell, cache, len, var tmp, indx, row, icell, cache, len,
table = c.table,
$tbodies = c.$tbodies, $tbodies = c.$tbodies,
$cell = $( cell ), $cell = $( cell ),
// update cache - format: function( s, table, cell, cellIndex ) // update cache - format: function( s, table, cell, cellIndex )
@ -1784,8 +1785,9 @@
} }
}, },
applyWidgetOptions : function( table, c ) { applyWidgetOptions : function( table ) {
var indx, widget, var indx, widget,
c = table.config,
len = c.widgets.length; len = c.widgets.length;
if ( len ) { if ( len ) {
for ( indx = 0; indx < len; indx++ ) { for ( indx = 0; indx < len; indx++ ) {
@ -1797,28 +1799,34 @@
} }
}, },
applyWidget : function( table, init, callback ) { addWidgetFromClass : function( table ) {
table = $( table )[ 0 ]; // in case this is called externally var len, indx,
var indx, len, names, widget, name, applied, time, time2, widgetClass,
c = table.config, c = table.config,
tableClass = ' ' + c.table.className + ' ', // look for widgets to apply from table class
widgets = []; // stop using \b otherwise this matches 'ui-widget-content' & adds 'content' widget
// prevent numerous consecutive widget applications regex = '\\s' + c.widgetClass.replace( ts.regex.templateName, '([\\w-]+)' ) + '\\s',
if ( init !== false && table.hasInitialized && ( table.isApplyingWidgets || table.isUpdating ) ) { widgetClass = new RegExp( regex, 'g' ),
return; // extract out the widget id from the table class (widget id's can include dashes)
} widget = ( ' ' + c.table.className + ' ' ).match( widgetClass );
if ( c.debug ) { time = new Date(); }
// look for widgets to apply from table class
// stop using \b otherwise this matches 'ui-widget-content' & adds 'content' widget
widgetClass = new RegExp( '\\s' + c.widgetClass.replace( ts.regex.templateName, '([\\w-]+)' ) + '\\s', 'g' );
// extract out the widget id from the table class (widget id's can include dashes)
widget = tableClass.match( widgetClass );
if ( widget ) { if ( widget ) {
len = widget.length; len = widget.length;
for ( indx = 0; indx < len; indx++ ) { for ( indx = 0; indx < len; indx++ ) {
c.widgets.push( widget[ indx ].replace( widgetClass, '$1' ) ); c.widgets.push( widget[ indx ].replace( widgetClass, '$1' ) );
} }
} }
},
applyWidget : function( table, init, callback ) {
table = $( table )[ 0 ]; // in case this is called externally
var indx, len, names, widget, name, applied, time, time2,
c = table.config,
widgets = [];
// prevent numerous consecutive widget applications
if ( init !== false && table.hasInitialized && ( table.isApplyingWidgets || table.isUpdating ) ) {
return;
}
if ( c.debug ) { time = new Date(); }
ts.addWidgetFromClass( table );
if ( c.widgets.length ) { if ( c.widgets.length ) {
table.isApplyingWidgets = true; table.isApplyingWidgets = true;
// ensure unique widget ids // ensure unique widget ids
@ -1857,7 +1865,7 @@
c.widgetInit[ name ] = true; c.widgetInit[ name ] = true;
if ( table.hasInitialized ) { if ( table.hasInitialized ) {
// don't reapply widget options on tablesorter init // don't reapply widget options on tablesorter init
ts.applyWidgetOptions( table, table.config ); ts.applyWidgetOptions( table );
} }
if ( typeof widget.init === 'function' ) { if ( typeof widget.init === 'function' ) {
applied = true; applied = true;