From 08b98084b0bbf76754550221d8c79016188b52b5 Mon Sep 17 00:00:00 2001 From: Mottie Date: Wed, 19 Feb 2014 18:21:16 -0600 Subject: [PATCH] Filter widget: fix js error on empty tables --- js/jquery.tablesorter.widgets.js | 2 +- js/jquery.tablesorter.widgets.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/jquery.tablesorter.widgets.js b/js/jquery.tablesorter.widgets.js index 75620248..6ae93ddb 100644 --- a/js/jquery.tablesorter.widgets.js +++ b/js/jquery.tablesorter.widgets.js @@ -850,7 +850,7 @@ ts.filter = { anyMatchNotAllowedTypes = [ 'range', 'notMatch', 'operators' ], // parse columns after formatter, in case the class is added at that point parsed = c.$headers.map(function(columnIndex) { - return c.parsers[columnIndex].parsed || ( ts.getData ? + return c.parsers && c.parsers[columnIndex].parsed || ( ts.getData ? ts.getData(c.$headers.filter('[data-column="' + columnIndex + '"]:last'), c.headers[columnIndex], 'filter') === 'parsed' : $(this).hasClass('filter-parsed') ); }).get(); diff --git a/js/jquery.tablesorter.widgets.min.js b/js/jquery.tablesorter.widgets.min.js index 3f2bd292..51aa2db4 100644 --- a/js/jquery.tablesorter.widgets.min.js +++ b/js/jquery.tablesorter.widgets.min.js @@ -7,7 +7,7 @@ c.addHeaderResizeEvent=function(b,a,c){var g;c=k.extend({},{timer:250},c);var e= c.addWidget({id:"uitheme",priority:10,format:function(b,a,d){var g,e,f,h,m=c.themes,q=a.$table,n=a.$headers,p=a.theme||"jui",l=m[p]||m.jui,v=l.sortNone+" "+l.sortDesc+" "+l.sortAsc;a.debug&&(g= new Date);q.hasClass("tablesorter-"+p)&&a.theme!==p&&b.hasInitialized||(""!==l.even&&(d.zebra[0]+=" "+l.even),""!==l.odd&&(d.zebra[1]+=" "+l.odd),q.find("caption").addClass(l.caption),b=q.removeClass(""===a.theme?"":"tablesorter-"+a.theme).addClass("tablesorter-"+p+" "+l.table).find("tfoot"),b.length&&b.find("tr").addClass(l.footerRow).children("th, td").addClass(l.footerCells),n.addClass(l.header).not(".sorter-false").bind("mouseenter.tsuitheme mouseleave.tsuitheme",function(a){k(this)["mouseenter"=== a.type?"addClass":"removeClass"](l.hover)}),n.find("."+c.css.wrapper).length||n.wrapInner('
'),a.cssIcon&&n.find("."+c.css.icon).addClass(l.icons),q.hasClass("hasFilters")&&n.find("."+c.css.filterRow).addClass(l.filterRow));k.each(n,function(){f=k(this);h=c.css.icon?f.find("."+c.css.icon):f;this.sortDisabled?(f.removeClass(v),h.removeClass(v+" "+l.icons)):(e=f.hasClass(c.css.sortAsc)?l.sortAsc:f.hasClass(c.css.sortDesc)? l.sortDesc:f.hasClass(c.css.header)?l.sortNone:"",f[e===l.sortNone?"removeClass":"addClass"](l.active),h.removeClass(v).addClass(e))});a.debug&&c.benchmark("Applying "+p+" theme",g)},remove:function(b,a,d){b=a.$table;a=a.theme||"jui";d=c.themes[a]||c.themes.jui;var g=b.children("thead").children(),e=d.sortNone+" "+d.sortDesc+" "+d.sortAsc;b.removeClass("tablesorter-"+a+" "+d.table).find(c.css.header).removeClass(d.header);g.unbind("mouseenter.tsuitheme mouseleave.tsuitheme").removeClass(d.hover+" "+ e+" "+d.active).find("."+c.css.filterRow).removeClass(d.filterRow);g.find("."+c.css.icon).removeClass(d.icons)}}); c.addWidget({id:"columns",priority:30,options:{columns:["primary","secondary","tertiary"]},format:function(b,a,d){var g,e,f,h,m,q,n,p,l=a.$table,v=a.$tbodies,s=a.sortList,u=s.length,w=d&&d.columns||["primary","secondary","tertiary"],x=w.length-1;n=w.join(" ");a.debug&&(g=new Date);for(f=0;f=]/g},types:{regex:function(b,a,d,g){if(c.filter.regex.regex.test(a)){var e; b=c.filter.regex.regex.exec(a);try{e=RegExp(b[1],b[2]).test(g)}catch(f){e=!1}return e}return null},operators:function(b,a,d,g,e,f,h,k,q){if(/^[<>]=?/.test(a)){var n,p;n=h.config;b=c.formatFloat(a.replace(c.filter.regex.operators,""),h);d=n.parsers[f];k=b;if(q[f]||"numeric"===d.type)n=d.format(""+a.replace(c.filter.regex.operators,""),h,n.$headers.eq(f),f),b="number"!==typeof b||""===n||isNaN(n)?b:n;n=!q[f]&&"numeric"!==d.type||isNaN(b)||!e?isNaN(g)?c.formatFloat(g.replace(c.filter.regex.nondigit, ""),h):c.formatFloat(g,h):e;/>/.test(a)&&(p=/>=/.test(a)?n>=b:n>b);/k&&(g=d,d=k,k=g);return a>=d&&a<=k||""===d||""===k}return null},wild:function(b,a,c,g,e,f,h,m,q,n){return/[\?|\*]/.test(a)||/\s+OR\s+/i.test(b)?(b=h.config,a=a.replace(/\s+OR\s+/gi,"|"),!b.$headers.filter('[data-column="'+f+'"]:last').hasClass("filter-match")&&/\|/.test(a)&&(a=k.isArray(n)?"("+a+")":"^("+a+")$"),RegExp(a.replace(/\?/g,"\\S{1}").replace(/\*/g, "\\S*")).test(g)):null},fuzzy:function(b,a,c,g){if(/^~/.test(a)){b=0;c=g.length;var e=a.slice(1);for(a=0;a'+(f.data("placeholder")|| f.attr("data-placeholder")||"")+"":"",g+='");a.$table.find("thead").find("select."+c.css.filter+'[data-column="'+h+'"]').append(g)}c.filter.buildDefault(b,!0);c.filter.bindSearch(b,a.$table.find("."+c.css.filter),!0);d.filter_external&&c.filter.bindSearch(b,d.filter_external);d.filter_hideFilters&&c.filter.hideFilters(b,a);a.showProcessing&&a.$table.bind("filterStart.tsfilter filterEnd.tsfilter",function(d,e){f=e?a.$table.find("."+c.css.header).filter("[data-column]").filter(function(){return""!== e[k(this).data("column")]}):"";c.isProcessing(b,"filterStart"===d.type,e?f:"")});a.debug&&c.benchmark("Applying Filter widget",q);a.$table.bind("tablesorter-initialized pagerInitialized",function(){m=c.filter.setDefaults(b,a,d)||[];m.length&&c.setFilters(b,m,!0);a.$table.trigger("filterFomatterUpdate");c.filter.checkFilters(b,m)});d.filter_initialized=!0;a.$table.trigger("filterInit")},setDefaults:function(b,a,d){var g=c.getFilters(b);d.filter_saveFilters&&c.storage&&(d=c.storage(b,"tablesorter-filters")|| [],(b=k.isArray(d))&&""===d.join("")||!b||(g=d));a.$table.data("lastSearch",g);return g},buildRow:function(b,a,d){var g,e,f,h=a.columns;e='';for(b=0;b";a.$filters=k(e+"").appendTo(a.$table.find("thead").eq(0)).find("td");for(b=0;b").appendTo(a.$filters.eq(b)):(d.filter_formatter&&k.isFunction(d.filter_formatter[b])?((e=d.filter_formatter[b](a.$filters.eq(b),b))&&0===e.length&&(e=a.$filters.eq(b).children("input")),e&&(0===e.parent().length||e.parent().length&&e.parent()[0]!==a.$filters[b])&&a.$filters.eq(b).append(e)):e=k('').appendTo(a.$filters.eq(b)),e&&e.attr("placeholder", g.data("placeholder")||g.attr("data-placeholder")||"")),e&&(g=(k.isArray(d.filter_cssFilter)?"undefined"!==typeof d.filter_cssFilter[b]?d.filter_cssFilter[b]||"":"":d.filter_cssFilter)||"",e.addClass(c.css.filter+" "+g).attr("data-column",b),f&&(e.addClass("disabled")[0].disabled=!0))},bindSearch:function(b,a,d){b=k(b)[0];a=k(a);if(a.length){var g=b.config,e=g.widgetOptions,f=e.filter_$externalFilters;!0!==d&&(e.filter_$anyMatch=a.filter('[data-column="all"]'),e.filter_$externalFilters=f&&f.length? e.filter_$externalFilters.add(a):a,c.setFilters(b,g.$table.data("lastSearch")||[],!1===d));a.attr("data-lastSearchTime",(new Date).getTime()).unbind("keyup search change").bind("keyup search change",function(a,d){k(this).attr("data-lastSearchTime",(new Date).getTime());if(27===a.which)this.value="";else if("number"===typeof e.filter_liveSearch&&this.value.lengtha.which&&8!==a.which&&!0===e.filter_liveSearch&&13!==a.which||37<=a.which&&40>= a.which||13!==a.which&&!1===e.filter_liveSearch))return;c.filter.searching(b,d||c.getFilters(b,!0),!0)});g.$table.bind("filterReset",function(){a.val("")})}},checkFilters:function(b,a,d){var g=b.config,e=g.widgetOptions,f=k.isArray(a),h=f?a:c.getFilters(b),m=(h||[]).join("");f&&c.setFilters(b,h,!1,!0!==d);e.filter_hideFilters&&g.$table.find("."+c.css.filterRow).trigger(""===m?"mouseleave":"mouseenter");if(g.lastCombinedFilter!==m||!1===a)if(!1===a&&(g.lastCombinedFilter=null),g.$table.trigger("filterStart", [h]),g.showProcessing)setTimeout(function(){c.filter.findRows(b,h,m);return!1},30);else return c.filter.findRows(b,h,m),!1},hideFilters:function(b,a){var d,g,e;a.$table.find("."+c.css.filterRow).addClass("hideme").bind("mouseenter mouseleave",function(a){d=k(this);clearTimeout(e);e=setTimeout(function(){/enter|over/.test(a.type)?d.removeClass("hideme"):k(document.activeElement).closest("tr")[0]!==d[0]&&""===c.getFilters(b).join("")&&d.addClass("hideme")},200)}).find("input, select").bind("focus blur", function(a){g=k(this).closest("tr");clearTimeout(e);e=setTimeout(function(){if(""===c.getFilters(b).join(""))g["focus"===a.type?"removeClass":"addClass"]("hideme")},200)})},findRows:function(b,a,d){if(b.config.lastCombinedFilter!==d){var g,e,f,h,m,q,n,p,l,v,s,u,w,x,B,z,y,D,C,A,L,E,G,H,I,J,M,r=b.config,t=r.widgetOptions,N=r.columns,K=r.$tbodies,O=["range","notMatch","operators"],F=r.$headers.map(function(a){return r.parsers[a].parsed||(c.getData?"parsed"===c.getData(r.$headers.filter('[data-column="'+ a+'"]:last'),r.headers[a],"filter"):k(this).hasClass("filter-parsed"))}).get();r.debug&&(L=new Date);for(q=0;qk.inArray(a,O)&&(z=c(E,G,I,J,M,N,b,t,F,H),null!==z))return C=z,!1}),A=null!==C?C:0<=(J+s).indexOf(G));for(l=0;l'+(p.data("placeholder")|| p.attr("data-placeholder")||"")+"";for(f=0;f"+n[g]+"":"";b.$table.find("thead").find("select."+c.css.filter+'[data-column="'+a+'"]')[d?"html":"append"](l)},buildDefault:function(b,a){var d,g,e=b.config,f=e.widgetOptions,h=e.columns;for(d=0;d=]/g},types:{regex:function(b,a,d,g){if(c.filter.regex.regex.test(a)){var e; b=c.filter.regex.regex.exec(a);try{e=RegExp(b[1],b[2]).test(g)}catch(f){e=!1}return e}return null},operators:function(b,a,d,g,e,f,h,k,q){if(/^[<>]=?/.test(a)){var n,p;n=h.config;b=c.formatFloat(a.replace(c.filter.regex.operators,""),h);d=n.parsers[f];k=b;if(q[f]||"numeric"===d.type)n=d.format(""+a.replace(c.filter.regex.operators,""),h,n.$headers.eq(f),f),b="number"!==typeof b||""===n||isNaN(n)?b:n;n=!q[f]&&"numeric"!==d.type||isNaN(b)||!e?isNaN(g)?c.formatFloat(g.replace(c.filter.regex.nondigit, ""),h):c.formatFloat(g,h):e;/>/.test(a)&&(p=/>=/.test(a)?n>=b:n>b);/k&&(g=d,d=k,k=g);return a>=d&&a<=k||""===d||""===k}return null},wild:function(b,a,c,g,e,f,h,m,q,n){return/[\?|\*]/.test(a)||/\s+OR\s+/i.test(b)?(b=h.config,a=a.replace(/\s+OR\s+/gi,"|"),!b.$headers.filter('[data-column="'+f+'"]:last').hasClass("filter-match")&&/\|/.test(a)&&(a=k.isArray(n)?"("+a+")":"^("+a+")$"),RegExp(a.replace(/\?/g,"\\S{1}").replace(/\*/g, "\\S*")).test(g)):null},fuzzy:function(b,a,c,g){if(/^~/.test(a)){b=0;c=g.length;var e=a.slice(1);for(a=0;a'+(f.data("placeholder")|| f.attr("data-placeholder")||"")+"":"",g+='");a.$table.find("thead").find("select."+c.css.filter+'[data-column="'+h+'"]').append(g)}c.filter.buildDefault(b,!0);c.filter.bindSearch(b,a.$table.find("."+c.css.filter),!0);d.filter_external&&c.filter.bindSearch(b,d.filter_external);d.filter_hideFilters&&c.filter.hideFilters(b,a);a.showProcessing&&a.$table.bind("filterStart.tsfilter filterEnd.tsfilter",function(d,e){f=e?a.$table.find("."+c.css.header).filter("[data-column]").filter(function(){return""!== e[k(this).data("column")]}):"";c.isProcessing(b,"filterStart"===d.type,e?f:"")});a.debug&&c.benchmark("Applying Filter widget",q);a.$table.bind("tablesorter-initialized pagerInitialized",function(){m=c.filter.setDefaults(b,a,d)||[];m.length&&c.setFilters(b,m,!0);a.$table.trigger("filterFomatterUpdate");c.filter.checkFilters(b,m)});d.filter_initialized=!0;a.$table.trigger("filterInit")},setDefaults:function(b,a,d){var g=c.getFilters(b);d.filter_saveFilters&&c.storage&&(d=c.storage(b,"tablesorter-filters")|| [],(b=k.isArray(d))&&""===d.join("")||!b||(g=d));a.$table.data("lastSearch",g);return g},buildRow:function(b,a,d){var g,e,f,h=a.columns;e='';for(b=0;b";a.$filters=k(e+"").appendTo(a.$table.find("thead").eq(0)).find("td");for(b=0;b").appendTo(a.$filters.eq(b)):(d.filter_formatter&&k.isFunction(d.filter_formatter[b])?((e=d.filter_formatter[b](a.$filters.eq(b),b))&&0===e.length&&(e=a.$filters.eq(b).children("input")),e&&(0===e.parent().length||e.parent().length&&e.parent()[0]!==a.$filters[b])&&a.$filters.eq(b).append(e)):e=k('').appendTo(a.$filters.eq(b)),e&&e.attr("placeholder", g.data("placeholder")||g.attr("data-placeholder")||"")),e&&(g=(k.isArray(d.filter_cssFilter)?"undefined"!==typeof d.filter_cssFilter[b]?d.filter_cssFilter[b]||"":"":d.filter_cssFilter)||"",e.addClass(c.css.filter+" "+g).attr("data-column",b),f&&(e.addClass("disabled")[0].disabled=!0))},bindSearch:function(b,a,d){b=k(b)[0];a=k(a);if(a.length){var g=b.config,e=g.widgetOptions,f=e.filter_$externalFilters;!0!==d&&(e.filter_$anyMatch=a.filter('[data-column="all"]'),e.filter_$externalFilters=f&&f.length? e.filter_$externalFilters.add(a):a,c.setFilters(b,g.$table.data("lastSearch")||[],!1===d));a.attr("data-lastSearchTime",(new Date).getTime()).unbind("keyup search change").bind("keyup search change",function(a,d){k(this).attr("data-lastSearchTime",(new Date).getTime());if(27===a.which)this.value="";else if("number"===typeof e.filter_liveSearch&&this.value.lengtha.which&&8!==a.which&&!0===e.filter_liveSearch&&13!==a.which||37<=a.which&&40>= a.which||13!==a.which&&!1===e.filter_liveSearch))return;c.filter.searching(b,d||c.getFilters(b,!0),!0)});g.$table.bind("filterReset",function(){a.val("")})}},checkFilters:function(b,a,d){var g=b.config,e=g.widgetOptions,f=k.isArray(a),h=f?a:c.getFilters(b),m=(h||[]).join("");f&&c.setFilters(b,h,!1,!0!==d);e.filter_hideFilters&&g.$table.find("."+c.css.filterRow).trigger(""===m?"mouseleave":"mouseenter");if(g.lastCombinedFilter!==m||!1===a)if(!1===a&&(g.lastCombinedFilter=null),g.$table.trigger("filterStart", [h]),g.showProcessing)setTimeout(function(){c.filter.findRows(b,h,m);return!1},30);else return c.filter.findRows(b,h,m),!1},hideFilters:function(b,a){var d,g,e;a.$table.find("."+c.css.filterRow).addClass("hideme").bind("mouseenter mouseleave",function(a){d=k(this);clearTimeout(e);e=setTimeout(function(){/enter|over/.test(a.type)?d.removeClass("hideme"):k(document.activeElement).closest("tr")[0]!==d[0]&&""===c.getFilters(b).join("")&&d.addClass("hideme")},200)}).find("input, select").bind("focus blur", function(a){g=k(this).closest("tr");clearTimeout(e);e=setTimeout(function(){if(""===c.getFilters(b).join(""))g["focus"===a.type?"removeClass":"addClass"]("hideme")},200)})},findRows:function(b,a,d){if(b.config.lastCombinedFilter!==d){var g,e,f,h,m,q,n,p,l,v,s,u,w,x,B,z,y,D,C,A,L,E,G,H,I,J,M,r=b.config,t=r.widgetOptions,N=r.columns,K=r.$tbodies,O=["range","notMatch","operators"],F=r.$headers.map(function(a){return r.parsers&&r.parsers[a].parsed||(c.getData?"parsed"===c.getData(r.$headers.filter('[data-column="'+ a+'"]:last'),r.headers[a],"filter"):k(this).hasClass("filter-parsed"))}).get();r.debug&&(L=new Date);for(q=0;qk.inArray(a,O)&&(z=c(E,G,I,J,M,N,b,t,F,H),null!==z))return C=z,!1}),A=null!==C?C:0<=(J+s).indexOf(G));for(l=0;l'+(p.data("placeholder")|| p.attr("data-placeholder")||"")+"";for(f=0;f"+n[g]+"":"";b.$table.find("thead").find("select."+c.css.filter+'[data-column="'+a+'"]')[d?"html":"append"](l)},buildDefault:function(b,a){var d,g,e=b.config,f=e.widgetOptions,h=e.columns;for(d=0;db.top&&c