1 line
1.4 KiB
JavaScript
1 line
1.4 KiB
JavaScript
|
!function(c){c.fn.stupidtable=function(e){return this.each(function(){var n=c(this);e=e||{},e=c.extend({},c.fn.stupidtable.default_sort_fns,e),n.on("click.stupidtable","thead th",function(){var t=c(this),i=0,s=c.fn.stupidtable.dir;t.parents("tr").find("th").slice(0,t.index()+1).each(function(){var t=c(this).attr("colspan")||1;i+=parseInt(t,10)}),--i;var o=t.data("sortDefault")||s.ASC;t.data("sortDir")&&(o=t.data("sortDir")===s.ASC?s.DESC:s.ASC);var r=t.data("sort")||null;null!==r&&(n.trigger("beforetablesort",{column:t.index(),direction:o}),n.css("display"),setTimeout(function(){var a=e[r];n.children("tbody").each(function(t,r){var e=[],n=c(r),r=n.children("tr").not("[data-sort-ignore]");r.each(function(t,r){var n=c(r).children().eq(i),a=n.data("sortValue"),n=void 0!==a?a:n.text();e.push([n,r])}),e.sort(function(t,r){return a(t[0],r[0])}),o!=s.ASC&&e.reverse(),r=c.map(e,function(t){return t[1]}),n.append(r)}),n.find("th").data("sortDir",null).removeClass("sorting-desc sorting-asc"),t.data("sortDir",o).addClass("sorting-"+o),n.trigger("aftertablesort",{column:t.index(),direction:o}),n.css("display")},10))})})},c.fn.stupidtable.dir={ASC:"asc",DESC:"desc"},c.fn.stupidtable.default_sort_fns={"int":function(t,r){return parseInt(t,10)-parseInt(r,10)},"float":function(t,r){return parseFloat(t)-parseFloat(r)},string:function(t,r){return t.localeCompare(r)},"string-ins":function(t,r){return t=t.toLocaleLowerCase(),r=r.toLocaleLowerCase(),t.localeCompare(r)}}}(jQuery);
|