diff --git a/docs/index.html b/docs/index.html index edaa764a..7ef30e1d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -481,7 +481,7 @@
  • custom (v2.3.6; v2.10.1)
  • custom searches (v2.17.5; v2.17.8)
  • formatter: jQuery UI widgets and HTML5 Elements (v2.7.7; v2.17.5).
  • -
  • formatter: select2 (v2.16.0; v2.17.5)
  • +
  • formatter: select2 (v2.16.0; v2.18.5)
  • Grouping rows widget: diff --git a/js/jquery.tablesorter.widgets-filter-formatter-select2.js b/js/jquery.tablesorter.widgets-filter-formatter-select2.js index c065573f..584347b0 100644 --- a/js/jquery.tablesorter.widgets-filter-formatter-select2.js +++ b/js/jquery.tablesorter.widgets-filter-formatter-select2.js @@ -1,4 +1,4 @@ -/*! Filter widget select2 formatter function - updated 7/17/2014 (v2.17.5) +/*! Filter widget select2 formatter function - updated 1/16/2015 (v2.18.5) * requires: jQuery 1.7.2+, tableSorter (FORK) 2.16+, filter widget 2.16+ and select2 v3.4.6+ plugin */ /*jshint browser:true, jquery:true, unused:false */ @@ -45,11 +45,17 @@ ts.filterFormatter.select2 = function($cell, indx, select2Def) { // this function updates the hidden input and adds the current values to the header cell text updateSelect2 = function() { var v = $cell.find('.select2').select2('val') || o.value || ''; + // convert array to string + if ($.isArray(v)) { v = v.join('\u0000'); } + // escape special regex characters (http://stackoverflow.com/a/9310752/145346) + v = v.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + // convert string back into an array + if (v.indexOf('\u0000')) { v = v.split('\u0000'); } $input - // add regex, so we filter exact numbers - .val( $.isArray(v) && v.length && v.join('') !== '' ? '/(' + matchPrefix + (v || []).join(matchSuffix + '|' + matchPrefix) + matchSuffix + ')/' : '' ) - .trigger('search').end() - .find('.select2').select2('val', v); + // add regex, so we filter exact numbers + .val( $.isArray(v) && v.length && v.join('') !== '' ? '/(' + matchPrefix + (v || []).join(matchSuffix + '|' + matchPrefix) + matchSuffix + ')/' : '' ) + .trigger('search').end() + .find('.select2').select2('val', v); // update sticky header cell if ($shcell.length) { $shcell @@ -99,7 +105,7 @@ ts.filterFormatter.select2 = function($cell, indx, select2Def) { c.$table.bind('filterFomatterUpdate', function(){ // value = '/(^x$|^y$)/' => 'x,y' var val = c.$table.data('lastSearch')[indx] || ''; - val = val.replace(/[/()$^]/g, '').split('|'); + val = val.replace(/^\/\(\^?/,'').replace(/\$\|\^/g, '|').replace(/\$?\)\/$/g,'').split('|'); $cell.find('.select2').select2('val', val); updateSelect2(); ts.filter.formatterUpdated($cell, indx);