mirror of
https://github.com/Mottie/tablesorter.git
synced 2025-01-12 15:24:21 +00:00
Filter: Select2 update after filter row rebuilt. See #1237
This commit is contained in:
parent
de54b36235
commit
6e81e5e2cc
@ -1,2 +1,2 @@
|
|||||||
/*! Widget: filter, select2 formatter function - updated 5/28/2016 (v2.26.2) */
|
/*! Widget: filter, select2 formatter function - updated 5/28/2016 (v2.26.2) */
|
||||||
!function(a){"use strict";var b=a.tablesorter||{};b.filterFormatter=b.filterFormatter||{},b.filterFormatter.select2=function(c,d,e){var f,g,h=a.extend({cellText:"",match:!0,value:"",multiple:!0,width:"100%"},e),i=c.closest("table")[0].config,j=i.widgetOptions,k=a('<input class="filter" type="hidden">').appendTo(c).bind("change"+i.namespace+"filter",function(){var a=this.value;a=a.replace(/[\/()$^]/g,"").split("|"),c.find(".select2").select2("val",a),r()}),l=i.$headerIndexed[d],m=l.hasClass(j.filter_onlyAvail),n=[],o=h.match?"":"^",p=h.match?"":"$",q=j.filter_ignoreCase?"i":"",r=function(){var b=!1,d=c.find(".select2").select2("val")||h.value||"";a.isArray(d)&&(b=!0,d=d.join("\x00")),d=d.replace(/[-[\]{}()*+?.,\/\\^$|#\s]/g,"\\$&"),b&&(d=d.split("\x00")),k.val(a.isArray(d)&&d.length&&""!==d.join("")?"/("+o+(d||[]).join(p+"|"+o)+p+")/"+q:"").trigger("search").end().find(".select2").select2("val",d),n.length&&n.find(".select2").select2("val",d)},s=function(){g=[],f=b.filter.getOptionSource(i.$table[0],d,m)||[],a.each(f,function(a,b){g.push({id:""+b.parsed,text:b.text})}),h.data=g};return l.toggleClass("filter-match",h.match),h.cellText&&c.prepend("<label>"+h.cellText+"</label>"),h.ajax&&!a.isEmptyObject(h.ajax)||h.data||(s(),m&&i.$table.bind("filterEnd",function(){s(),c.add(n).find(".select2").select2(h)})),a('<input class="select2 select2-'+d+'" type="hidden" />').val(h.value).appendTo(c).select2(h).bind("change",function(){r()}),i.$table.bind("filterFomatterUpdate",function(){var a=i.$table.data("lastSearch")[d]||"";a=a.replace(/^\/\(\^?/,"").replace(/\$\|\^/g,"|").replace(/\$?\)\/$/g,"").split("|"),c.find(".select2").select2("val",a),r(),b.filter.formatterUpdated(c,d)}),i.$table.bind("stickyHeadersInit",function(){n=i.widgetOptions.$sticky.find("."+b.css.filterRow).children().eq(d).empty(),a('<input class="select2 select2-'+d+'" type="hidden">').val(h.value).appendTo(n).select2(h).bind("change",function(){c.find(".select2").select2("val",n.find(".select2").select2("val")),r()}),h.cellText&&n.prepend("<label>"+h.cellText+"</label>")}),i.$table.bind("filterReset",function(){c.find(".select2").select2("val",h.value||""),setTimeout(function(){r()},0)}),r(),k}}(jQuery);
|
!function(a){"use strict";var b=a.tablesorter||{};b.filterFormatter=b.filterFormatter||{},b.filterFormatter.select2=function(c,d,e){var f,g,h=a.extend({cellText:"",match:!0,value:"",multiple:!0,width:"100%"},e),i=c.addClass("select2col"+d).closest("table")[0].config,j=i.widgetOptions,k=a('<input class="filter" type="hidden">').appendTo(c).bind("change"+i.namespace+"filter",function(){var a=this.value;a=a.replace(/[\/()$^]/g,"").split("|"),c.find(".select2").select2("val",a),r()}),l=i.$headerIndexed[d],m=l.hasClass(j.filter_onlyAvail),n=[],o=h.match?"":"^",p=h.match?"":"$",q=j.filter_ignoreCase?"i":"",r=function(){var b=!1,d=c.find(".select2").select2("val")||h.value||"";a.isArray(d)&&(b=!0,d=d.join("\x00")),d=d.replace(/[-[\]{}()*+?.,\/\\^$|#\s]/g,"\\$&"),b&&(d=d.split("\x00")),k.val(a.isArray(d)&&d.length&&""!==d.join("")?"/("+o+(d||[]).join(p+"|"+o)+p+")/"+q:"").trigger("search").end().find(".select2").select2("val",d),n.length&&n.find(".select2").select2("val",d)},s=function(){g=[],f=b.filter.getOptionSource(i.$table[0],d,m)||[],a.each(f,function(a,b){g.push({id:""+b.parsed,text:b.text})}),h.data=g};return l.toggleClass("filter-match",h.match),h.cellText&&c.prepend("<label>"+h.cellText+"</label>"),h.ajax&&!a.isEmptyObject(h.ajax)||h.data||(s(),m&&i.$table.bind("filterEnd",function(){s(),c.add(n).find(".select2").select2(h)})),a('<input class="select2 select2-'+d+'" type="hidden" />').val(h.value).appendTo(c).select2(h).bind("change",function(){r()}),i.$table.bind("filterFomatterUpdate",function(){var a=i.$table.data("lastSearch")[d]||"";a=a.replace(/^\/\(\^?/,"").replace(/\$\|\^/g,"|").replace(/\$?\)\/$/g,"").split("|"),c=i.$table.find(".select2col"+d),c.find(".select2").select2("val",a),r(),b.filter.formatterUpdated(c,d)}),i.$table.bind("stickyHeadersInit",function(){n=i.widgetOptions.$sticky.find("."+b.css.filterRow).children().eq(d).empty(),a('<input class="select2 select2-'+d+'" type="hidden">').val(h.value).appendTo(n).select2(h).bind("change",function(){c.find(".select2").select2("val",n.find(".select2").select2("val")),r()}),h.cellText&&n.prepend("<label>"+h.cellText+"</label>")}),i.$table.bind("filterReset",function(){c.find(".select2").select2("val",h.value||""),setTimeout(function(){r()},0)}),r(),k}}(jQuery);
|
@ -25,7 +25,9 @@
|
|||||||
|
|
||||||
}, select2Def ),
|
}, select2Def ),
|
||||||
arry, data,
|
arry, data,
|
||||||
c = $cell.closest('table')[0].config,
|
// add class to $cell since it may point to a removed DOM node
|
||||||
|
// after a "refreshWidgets"; see #1237
|
||||||
|
c = $cell.addClass('select2col' + indx).closest('table')[0].config,
|
||||||
wo = c.widgetOptions,
|
wo = c.widgetOptions,
|
||||||
// Add a hidden input to hold the range values
|
// Add a hidden input to hold the range values
|
||||||
$input = $('<input class="filter" type="hidden">')
|
$input = $('<input class="filter" type="hidden">')
|
||||||
@ -118,6 +120,7 @@
|
|||||||
// value = '/(^x$|^y$)/' => 'x,y'
|
// value = '/(^x$|^y$)/' => 'x,y'
|
||||||
var val = c.$table.data('lastSearch')[indx] || '';
|
var val = c.$table.data('lastSearch')[indx] || '';
|
||||||
val = val.replace(/^\/\(\^?/, '').replace(/\$\|\^/g, '|').replace(/\$?\)\/$/g, '').split('|');
|
val = val.replace(/^\/\(\^?/, '').replace(/\$\|\^/g, '|').replace(/\$?\)\/$/g, '').split('|');
|
||||||
|
$cell = c.$table.find('.select2col' + indx);
|
||||||
$cell.find('.select2').select2('val', val);
|
$cell.find('.select2').select2('val', val);
|
||||||
updateSelect2();
|
updateSelect2();
|
||||||
ts.filter.formatterUpdated($cell, indx);
|
ts.filter.formatterUpdated($cell, indx);
|
||||||
|
Loading…
Reference in New Issue
Block a user