UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

3 lines (2 loc) 3.81 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("kendo.core.js"),require("kendo.icons.js")):"function"==typeof define&&define.amd?define(["exports","kendo.core.min","kendo.icons"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).kendo=e.kendo||{},e.kendo._globals=e.kendo._globals||{},e.kendo._globals.Columnsorter={}))}(this,(function(e){!function(e,t){var n=window.kendo,o=n.ui,r=o.Widget,i="dir",s="asc",a="single",l="mixed",d="field",c="desc",f=".kendoColumnSorter",k=".k-link",u="aria-sort",p=r.extend({init:function(e,t){var n,o=this;r.fn.init.call(o,e,t),o._refreshHandler=o.refresh.bind(o),o.dataSource=o.options.dataSource.bind("change",o._refreshHandler),o.directions=o.options.initialDirection===s?[s,c]:[c,s],(n=o.element.find(k))[0]||(n=o.element.wrapInner('<a class="k-link" href="#"/>').find(k)),o.link=n,o.element.on("click"+f,o._click.bind(o))},options:{name:"ColumnSorter",mode:a,allowUnsort:!0,compare:null,filter:"",initialDirection:s,showIndexes:!1},events:["change"],destroy:function(){var e=this;r.fn.destroy.call(e),e.element.off(f),e.dataSource.unbind("change",e._refreshHandler),e._refreshHandler=e.element=e.link=e.dataSource=null},refresh:function(o){if(!o||"itemchange"!==o.action&&"sync"!==o.action){var r,a,l,f,k,p,m,h,g=this,v=g.dataSource.sort()||[],_=g.element,b=_.attr(n.attr(d)),x=(g.dataSource._sortFields||{})[b];_.removeAttr(n.attr(i)),_.removeAttr(u),x&&(r=x.dir,_.attr(n.attr(i),r),f=x.index),_.is("th")&&x&&(a=function(e){var t=null;e.is("th")&&((t=e.closest("table")).parent().hasClass("k-grid-header-wrap")?t=t.closest(".k-grid").find(".k-grid-content > table"):t.parent().hasClass("k-grid-header-locked")&&(t=t.closest(".k-grid").find(".k-grid-content-locked > table")));return t}(_),a&&(_.attr(n.attr("index"))?(k=_.closest("table"),p=k.find("tr:not(.k-filter-row)"),m=n.attr("index"),h=p.find("th["+m+"]:visible"),l=[].sort.call(h,(function(n,o){n=e(n),o=e(o);var r=n.attr(m),i=o.attr(m);return r===t&&(r=e(n).index()),i===t&&(i=e(o).index()),(r=parseInt(r,10))>(i=parseInt(i,10))?1:r<i?-1:0})).index(_)):l=_.parent().children(":visible").index(_),a.find("col:not(.k-group-col):not(.k-hierarchy-col)").eq(l).toggleClass("k-sorted",r!==t))),_.toggleClass("k-sorted",r!==t),_.find(".k-i-sort-asc-small,.k-i-sort-desc-small,.k-svg-i-sort-asc-small,.k-svg-i-sort-desc-small,.k-sort-order,.k-sort-icon").remove(),r===s?(e('<span class="k-sort-icon">'+n.ui.icon("sort-asc-small")+"</span>").appendTo(g.link),_.attr(u,"ascending")):r===c?(e('<span class="k-sort-icon">'+n.ui.icon("sort-desc-small")+"</span>").appendTo(g.link),_.attr(u,"descending")):_.attr(u,"none"),g.options.showIndexes&&v.length>1&&f&&e('<span class="k-sort-order" />').html(f).appendTo(g.link)}},_toggleSortDirection:function(e){var n=this.directions;return e===n[n.length-1]&&this.options.allowUnsort?t:n[0]===e?n[1]:n[0]},_click:function(e){var o,r,s=this,c=s.element,f=c.attr(n.attr(d)),k=c.attr(n.attr(i)),u=s.options,p=null===s.options.compare?t:s.options.compare,m=s.dataSource.sort()||[],h=e.ctrlKey||e.metaKey;if(e.preventDefault(),(!u.filter||c.is(u.filter))&&(k=this._toggleSortDirection(k),!this.trigger("change",{sort:{field:f,dir:k,compare:p}}))){if(u.mode===a||u.mode===l&&!h)m=[{field:f,dir:k,compare:p}];else if("multiple"===u.mode||u.mode===l&&h){for(o=0,r=m.length;o<r;o++)if(m[o].field===f){m.splice(o,1);break}m.push({field:f,dir:k,compare:p})}this.dataSource.options.endless&&c.closest(".k-grid").getKendoGrid()._resetEndless(),this.dataSource.sort(m)}}});o.plugin(p)}(window.kendo.jQuery);var t=kendo;e.__meta__={id:"columnsorter",name:"Column Sorter",category:"framework",depends:["core","icons"],advanced:!0},e.default=t,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=kendo.columnsorter.min.js.map