Open lesilent opened 5 years ago
Mottie, I think I have a fix for this. The source of this problem is in the applyWidgetOptions function line 2000:
$.extend( true, ts.defaults.widgetOptions, widget.options );
This, in effect, overwrites any default widgetOptions that the might be assigned directly (eg. jQuery.tablesorter.defaults.widgetOptions.filter_cssFilter = 'form-control'; ).
The solution would be to make a copy of the existing defaults.widgetOptions, and then re-apply them after the widget.options has been applied, like so:
var tmp = jQuery.extend(true, {}, ts.defaults.widgetOptions);
$.extend( true, ts.defaults.widgetOptions, widget.options, tmp );
Actually, widget.options
comes directly from the widget on initialization, not the user settings for the widget, those go into the config
. So that shouldn't be an issue since the options being added shouldn't already exist in the defaults.
I'm referring to when a default widgetOption is set directly:
jQuery.tablesorter.defaults.widgetOptions.filter_cssFilter = 'form-control';
c = $.extend( true, {}, ts.defaults, settings, ts.instanceMethods );
The custom filter_CssFilter widget option is in both the config and the defaults, ie:
c.widgetOptions.filter_cssFilter = 'form-control'; jQuery.tablesorter.defaults.widgetOptions.filter_cssFilter = 'form-control';
c.widgetOptions = $.extend( true, wo, c.widgetOptions );
Initially, the custom widget option is still in both the config and the defaults, ie:
c.widgetOptions.filter_cssFilter = 'form-control'; jQuery.tablesorter.defaults.widgetOptions.filter_cssFilter = 'form-control';
$.extend( true, ts.defaults.widgetOptions, widget.options );
The custom widget option is still in the config, but now the default.widgetOtions has been overwritten by the widget.options, ie:
c.widgetOptions.filter_cssFilter = 'form-control'; jQuery.tablesorter.defaults.widgetOptions.filter_cssFilter = '';
TLDR: Currently, you can set default options directly (eg. jQuery.tablesorter.defaults.theme = 'bootstrap') but you cannot set default widgetOptions (eg. jQuery.tablesorter.defaults.widgetOptions.filter_cssFilter = 'form-control';) that "stick" since they get overwritten after first use by the applyWidgetOptions function.
When extending the default widgetOptions, they get overwritten after they've been applied to a table. I believe this issue might be the same as the one in #1356 (which I think is still an issue even with the newest version). Below is my example.
https://jsbin.com/boxujocagu/1/edit?html,output
I noticed the problem when upgrading from an older version.