You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
4 lines
2.5 KiB
JavaScript
4 lines
2.5 KiB
JavaScript
/*! AlphabetSearch for DataTables v1.0.0
|
|
* 2014 SpryMedia Ltd - datatables.net/license
|
|
*/
|
|
!function(){function n(a,t,e){t.empty(),t.append("Search: ");var a=a.column(e.column).data(),n=function(a,t){for(var e,n={},i=0,r=a.length;i<r;i++)n[e=t.caseSensitive?a[i].toString().replace(/<.*?>/g,"").charAt(0):a[i].toString().replace(/<.*?>/g,"").charAt(0).toUpperCase()]?n[e]++:n[e]=1;return n}(a,e);if($('<span class="clear active"/>').data("letter","").data("match-count",a.length).html("None").appendTo(t),e.numbers)for(var i=0;i<10;i++){var r=String.fromCharCode(48+i);$("<span/>").data("letter",r).data("match-count",n[r]||0).addClass(n[r]?"":"empty").html(r).appendTo(t)}for(i=0;i<26;i++){r=String.fromCharCode(65+i);$("<span/>").data("letter",r).data("match-count",n[r]||0).addClass(n[r]?"":"empty").html(r).appendTo(t)}if(e.caseSensitive)for(i=0;i<26;i++){r=String.fromCharCode(97+i);$("<span/>").data("letter",r).data("match-count",n[r]||0).addClass(n[r]?"":"empty").html(r).appendTo(t)}$('<div class="alphabetInfo"></div>').appendTo(t)}$.fn.dataTable.Api.register("alphabetSearch()",function(t){return this.iterator("table",function(a){a.alphabetSearch=t}),this}),$.fn.dataTable.Api.register("alphabetSearch.recalc()",function(a){return this.iterator("table",function(a){n(new $.fn.dataTable.Api(a),$("div.alphabet",this.table().container()))}),this}),$.fn.dataTable.ext.search.push(function(a,t){if(!a.alphabetSearch)return!0;var e;if(void 0!==a.oInit.alphabet?(e=void 0!==a.oInit.alphabet.column?a.oInit.alphabet.column:0,void 0!==a.oInit.alphabet.caseSensitive&&a.oInit.alphabet.caseSensitive):(e=0,!1)){if(t[e].charAt(0)===a.alphabetSearch)return!0}else if(t[e].charAt(0).toUpperCase()===a.alphabetSearch)return!0;return!1}),$.fn.dataTable.AlphabetSearch=function(a){var t=new $.fn.dataTable.Api(a),e=$('<div class="alphabet"/>'),a=$.extend({column:0,caseSensitive:!1,numbers:!1},t.init().alphabet);n(t,e,a),e.on("click","span",function(){e.find(".active").removeClass("active"),$(this).addClass("active"),t.alphabetSearch($(this).data("letter")).draw()}),e.on("mouseenter","span",function(){e.find("div.alphabetInfo").css({opacity:1,left:$(this).position().left,width:$(this).width()}).html($(this).data("match-count"))}).on("mouseleave","span",function(){e.find("div.alphabetInfo").css("opacity",0)}),this.node=function(){return e}},$.fn.DataTable.AlphabetSearch=$.fn.dataTable.AlphabetSearch,$.fn.dataTable.ext.feature.push({fnInit:function(a){return new $.fn.dataTable.AlphabetSearch(a).node()},cFeature:"A"})}(); |