/*!@license
 * Infragistics.Web.ClientUI Grid Sorting 21.2.12
 *
 * Copyright (c) 2011-2022 Infragistics Inc.
 *
 * http://www.infragistics.com/
 *
 * Depends on:
 *	jquery-1.9.1.js
 *	jquery.ui.core.js
 *	jquery.ui.widget.js
  *	infragistics.ui.widget.js
 *	infragistics.ui.grid.framework.js
 *	infragistics.ui.shared.js
 *	infragistics.dataSource.js
 *	infragistics.util.js
 *	infragistics.ui.grid.shared.js
 *	infragistics.ui.grid.featurechooser.js
 */
(function(factory){if(typeof define==="function"&&define.amd){define(["./infragistics.ui.grid.featurechooser"],factory)}else{return factory(jQuery)}})(function($){"use strict";$.widget("ui.igGridSorting",$.ui.igWidget,{css:{sortableColumnHeader:"ui-iggrid-sortableheader ui-state-default",sortableColumnHeaderActive:"ui-iggrid-sortableheaderactive ui-state-active",sortableColumnHeaderHover:"ui-iggrid-sortableheaderhover ui-state-hover",sortableColumnHeaderFocus:"ui-iggrid-sortableheaderfocus ui-state-focus",ascendingColumnHeader:"ui-iggrid-colheaderasc",descendingColumnHeader:"ui-iggrid-colheaderdesc",ascendingColumn:"ui-iggrid-colasc ui-state-highlight",descendingColumn:"ui-iggrid-coldesc ui-state-highlight",sortIndicator:"ui-iggrid-colindicator",fcSortIndicatorAscending:"ui-iggrid-featurechooser-li-iconcontainer ui-icon ui-iggrid-icon-sort-a-z",fcSortIndicatorDescending:"ui-iggrid-featurechooser-li-iconcontainer ui-icon ui-iggrid-icon-sort-z-a",sortIndicatorAscending:"ui-iggrid-colindicator-asc ui-icon ui-icon-arrowthick-1-n",sortIndicatorDescending:"ui-iggrid-colindicator-desc ui-icon ui-icon-arrowthick-1-s",dialogSortedColumns:"ui-iggrid-sorting-dialog-sortedcolumns",dialogUnsortedColumns:"ui-iggrid-sorting-dialog-unsortedcolumns",dialogUnsortedColumnsSortByButton:"ui-iggrid-sorting-dialog-unsortedcolumns-sortbybutton",dialogAsdDescButton:"ui-iggrid-sorting-dialog-ascdescbutton",modalDialogSortByColumn:"ui-iggrid-sorting-dialog-sortbybutton",dialogSortedColumnsItem:"ui-widget-content",dialogUnsortedColumnsItem:"ui-widget-content",dialogButtonAsc:"ui-button ui-corner-all ui-button-icon-only ig-sorting-indicator",dialogButtonAscIcon:"ui-button-icon-primary ui-icon ui-icon-arrowthick-1-n",dialogButtonDesc:"ui-button ui-corner-all ui-button-icon-only ig-sorting-indicator",dialogButtonDescIcon:"ui-button-icon-primary ui-icon ui-icon-arrowthick-1-s",dialogButtonUnsort:"ui-iggrid-sorting-dialog-sortbybuttons ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-igbutton ui-widget-content ui-igbutton-remove",dialogButtonUnsortContainer:"ui-button-icon-primary ui-icon ui-icon-circle-close",dialogSortedColumnTextContainer:"ui-iggrid-dialog-text",dialogItemText:"ui-iggrid-dialog-text",dialogButtonsHover:"ui-state-hover",featureChooserModalDialogIcon:"ui-icon ui-iggrid-icon-multiple-sorting"},options:{type:null,caseSensitive:false,applySortedColumnCss:true,sortUrlKey:null,sortUrlKeyAscValue:null,sortUrlKeyDescValue:null,mode:"single",customSortFunction:null,firstSortDirection:"ascending",modalDialogSortOnClick:false,modalDialogSortByButtonText:undefined,modalDialogResetButtonLabel:undefined,modalDialogCaptionButtonDesc:undefined,modalDialogCaptionButtonAsc:undefined,modalDialogCaptionButtonUnsort:undefined,featureChooserText:undefined,unsortedColumnTooltip:undefined,modalDialogCaptionText:undefined,modalDialogButtonApplyText:undefined,modalDialogButtonCancelText:undefined,featureChooserSortAsc:undefined,featureChooserSortDesc:undefined,locale:{sortedColumnTooltip:undefined,unsortedColumnTooltip:undefined,ascending:undefined,descending:undefined,modalDialogSortByButtonText:undefined,modalDialogResetButton:undefined,modalDialogCaptionButtonDesc:undefined,modalDialogCaptionButtonAsc:undefined,modalDialogCaptionButtonUnsort:undefined,featureChooserText:undefined,modalDialogCaptionText:undefined,modalDialogButtonApplyText:undefined,modalDialogButtonCancelText:undefined,featureChooserSortAsc:undefined,featureChooserSortDesc:undefined},modalDialogWidth:350,modalDialogHeight:"",modalDialogAnimationDuration:200,columnSettings:[{columnKey:null,columnIndex:null,firstSortDirection:null,currentSortDirection:null,allowSorting:true,compareFunc:null}],persist:true,sortingDialogContainment:"owner",dialogWidget:"igGridModalDialog",inherit:false},renderInFeatureChooser:true,events:{columnSorting:"columnSorting",columnSorted:"columnSorted",modalDialogOpening:"modalDialogOpening",modalDialogOpened:"modalDialogOpened",modalDialogMoving:"modalDialogMoving",modalDialogClosing:"modalDialogClosing",modalDialogClosed:"modalDialogClosed",modalDialogContentsRendering:"modalDialogContentsRendering",modalDialogContentsRendered:"modalDialogContentsRendered",modalDialogSortingChanged:"modalDialogSortingChanged",modalDialogButtonUnsortClick:"modalDialogButtonUnsortClick",modalDialogSortClick:"modalDialogSortClick",modalDialogButtonApplyClick:"modalDialogButtonApplyClick",modalDialogButtonResetClick:"modalDialogButtonResetClick"},_createWidget:function(){this.options.columnSettings=[];this._superApply(arguments)},_create:function(){var self=this;this._headers=[];this._clickHandler=function(event){var th,id,scrLeft,$scrContainer,colKey;id=$(event.target).closest(".ui-iggrid").attr("id").replace("_container","");if(self.grid.element.attr("id")!==id){return}th=$(event.currentTarget).closest("th");if(th.attr("data-skip")!=="true"&&(self.grid._isMultiColumnGrid!==true||th.attr("data-isheadercell")==="true")){colKey=th.attr("id").replace(self.grid.id()+"_","");if(!self._checkSortingAllowed(colKey)){return}self._handleSort(event);scrLeft=$("#"+self.grid.id()+"_hscroller").scrollLeft();if(scrLeft>0){if(self.grid.options.fixedHeaders===true){self.grid.headersTable().parent().scrollLeft(scrLeft)}if(self.grid.options.fixedFooters===true){self.grid.footersTable().parent().scrollLeft(scrLeft)}$scrContainer=self.grid.scrollContainer();if(!$scrContainer.length){$scrContainer=self.grid._vdisplaycontainer()}$scrContainer.scrollLeft(scrLeft)}}};this._dragStartHandler=function(event){var id,noCancel=true;noCancel=self.grid._trigger("headercelldragcancel",event,{});if(noCancel){id=$(event.target).closest(".ui-iggrid").attr("id").replace("_container","");if(self.grid.element.attr("id")!==id){return}event.stopPropagation();event.preventDefault()}else{return true}return false};this._mouseOverHandler=function(event){var id,$target=$(event.currentTarget),cs,colKey;id=$(event.target).closest(".ui-iggrid").attr("id").replace("_container","");if(self.grid.element.attr("id")!==id){return}colKey=$target.closest("th").attr("id");if(colKey){colKey=colKey.replace(id+"_","");cs=self._getColumnSettingByKey(colKey);if(cs&&cs.allowSorting!==false){$target.addClass(self.css.sortableColumnHeaderHover)}}};this._mouseOutHandler=function(event){var id;id=$(event.target).closest(".ui-iggrid").attr("id").replace("_container","");if(self.grid.element.attr("id")!==id){return}$(event.currentTarget).removeClass(self.css.sortableColumnHeaderHover)};$("#"+this.element[0].id).delegate("thead th",{click:this._clickHandler,mouseover:this._mouseOverHandler,mouseout:this._mouseOutHandler});$("#"+this.element[0].id+" thead th").bind("dragstart",this._dragStartHandler);$("#"+this.element[0].id+"_headers thead th").bind("dragstart",this._dragStartHandler);$(document).delegate("#"+this.element[0].id+"_headers thead th",{click:this._clickHandler,mouseover:this._mouseOverHandler,mouseout:this._mouseOutHandler});this._keyDownHandler=function(event){self._handleSortKb(event)};this._focusHandler=function(event){self._handleFocusKb(event)};this._blurHandler=function(event){self._handleBlurKb(event)};$("#"+this.element[0].id).delegate("thead th",{keydown:this._keyDownHandler,focus:this._focusHandler,blur:this._blurHandler});$(document).delegate("#"+this.element[0].id+"_headers thead th",{keydown:this._keyDownHandler,focus:this._focusHandler,blur:this._blurHandler})},changeGlobalLanguage:function(){},changeGlobalRegional:function(){},_changeLocaleForModalDialog:function(){var $button,$modalDialog=this._getModalDialog();if($modalDialog.length){$modalDialog[this.options.dialogWidget]({locale:{buttonApplyText:this._getLocaleValue("modalDialogButtonApplyText"),buttonCancelText:this._getLocaleValue("modalDialogButtonCancelText"),modalDialogCaptionText:this._getLocaleValue("modalDialogCaptionText")}});$button=this._getDialogClearAllButton();if($button.length){$button.igButton("option","labelText",this._getLocaleValue("modalDialogResetButton"))}$.ui.igWidget.prototype.changeLocale.call(this,$modalDialog)}},_changeLocaleForFeatureChooser:function(){var fc=this.grid.element.data("igGridFeatureChooser");if(fc&&this.renderInFeatureChooser){fc._removeFeature("SortingAscending");fc._removeFeature("SortingDescending");fc._removeFeature("MultipleSorting");this._featureChooserInitialized=false;this._initFC()}},_changeLocaleForThs:function(){var self=this;this.grid.headersTable().find("th").each(function(){var $th=$(this),sortDir=$th.attr("aria-sort");if(sortDir){self._setHeaderAttributes($th,sortDir)}else{self._removeHeaderAttributes($th)}})},changeLocale:function(){this._changeLocaleForModalDialog();this._changeLocaleForFeatureChooser();this._changeLocaleForThs()},_registerWidget:$.noop,_unregisterWidget:$.noop,_setOption:function(key,value){var $modalDialog=this._getModalDialog();this._super(key,value);switch(key){case"type":throw new Error(this._getLocaleValue("optionChangeNotSupported").replace("{optionName}",key));case"caseSensitive":this.grid.dataSource.settings.sorting.caseSensitive=this.options.caseSensitive;break;case"modalDialogSortOnClick":$modalDialog.remove();this._renderMultipleSortingDialog();break;case"modalDialogAnimationDuration":$modalDialog[this.options.dialogWidget]("option","animationDuration",value);break;case"modalDialogWidth":$modalDialog[this.options.dialogWidget]("option","modalDialogWidth",value);break;case"modalDialogHeight":$modalDialog[this.options.dialogWidget]("option","modalDialogHeight",value);break;default:break}},_handleSortKb:function(event){if($(event.target).attr("id")===undefined||$(event.target).attr("id")===null){return}var $el=$(event.target),key=$el.attr("id").replace(this.grid.element.attr("id")+"_",""),id;id=$el.closest(".ui-iggrid").attr("id").replace("_container","");if(this.grid.element.attr("id")!==id){return}if(event.keyCode===$.ui.keyCode.ENTER||event.keyCode===$.ui.keyCode.SPACE){if(this._checkSortingAllowed(key)){if(event.shiftKey){this.unsortColumn(key,$el)}else{if(this.sortColumn(key,null,$el)){this._clearActiveHeader();$el.addClass(this.css.sortableColumnHeaderActive);this._currentActiveHeader=$el}}}event.stopPropagation();event.preventDefault()}},_handleFocusKb:function(event){if(this._resizing&&this._resizing._resizing){return}var $target=$(event.target),id=$target.closest(".ui-iggrid").attr("id").replace("_container",""),colId=$target.closest("th").attr("id"),colKey;if(!colId){return}colKey=colId.replace(this.grid.id()+"_","");if(this.grid.element.attr("id")!==id||$target.attr("data-fixing-indicator")!==undefined||!this._checkSortingAllowed(colKey)||!$target.is("th")){return}$target.addClass(this.css.sortableColumnHeaderFocus)},_handleBlurKb:function(event){var id=$(event.target).closest(".ui-iggrid").attr("id").replace("_container","");if(this.grid.element.attr("id")!==id){return}$(event.target).removeClass(this.css.sortableColumnHeaderFocus)},_handleSort:function(event){if(this._resizing&&this._resizing._resizing){this._resizing._resizing=false;return}var $currentTarget=$(event.currentTarget),$th=$currentTarget.closest("th"),key=$th.attr("id").replace(this.grid.element.attr("id")+"_",""),isShiftClicked=false;this._clearActiveHeader();isShiftClicked=event.shiftKey;if(isShiftClicked){this.unsortColumn(key,$th)}else{if(this.sortColumn(key,null,$currentTarget)){$currentTarget.addClass(this.css.sortableColumnHeaderActive);this._currentActiveHeader=$th}}event.stopPropagation();event.preventDefault()},_checkSortingAllowed:function(colKey){var expr,s=this._getColumnSettingByKey(colKey);if(!s||s.allowSorting===false){return false}expr=this._findExpressionByColKey(colKey);if(expr&&expr.isGroupBy){return false}return true},_initLoadingIndicator:function(){this._loadingIndicator=this.grid.container().length>0?this.grid.container().igLoading().data("igLoading").indicator():this.grid.element.igLoading().data("igLoading").indicator()},_getHeaderCellByIdentifier:function(identifier){var $headerCell,colKey;if($.type(identifier)==="number"){colKey=this.grid.options.columns[identifier].key}else{colKey=identifier}$headerCell=$("#"+this.grid.element[0].id+"_"+colKey);return $headerCell},_removeHeaderAttributes:function($header){$header.attr({title:this._getLocaleValue("unsortedColumnTooltip"),"data-localeid":"unsortedColumnTooltip"}).removeAttr("aria-sort")},_setHeaderAttributes:function($header,sortDir){if(!sortDir){return}$header.attr({title:sortDir.startsWith("asc")?this._getLocaleValue("sortedColumnTooltip").replace("${direction}",this._getLocaleValue("ascending")):this._getLocaleValue("sortedColumnTooltip").replace("${direction}",this._getLocaleValue("descending")),"aria-sort":sortDir,"data-localeid":"sortedColumnTooltip","data-localeattr":"title"})},sortColumn:function(index,direction,header){var colKey,expr,noCancel=true,s,i,newDir,apiCall=!header,sortingNewExprs,curNewExpr,compareFunc;this._activeSortedCol=null;if($.type(index)==="number"){colKey=this.grid.options.columns[index].key}else{colKey=index}header=header||$("#"+this.grid.element[0].id+"_"+colKey);this._curColKey=colKey;expr=this.grid.dataSource.settings.sorting.expressions;s=this._getColumnSettingByKey(colKey);if(apiCall){this._clearActiveHeader()}if(!s||!apiCall&&!this._checkSortingAllowed(colKey)){return}if(direction){newDir=direction}else{if(!s.currentSortDirection||!s.currentSortDirection.startsWith("asc")&&!s.currentSortDirection.startsWith("desc")){newDir=s.firstSortDirection===undefined?this.options.firstSortDirection:s.firstSortDirection}else{newDir=s.currentSortDirection&&s.currentSortDirection.indexOf("asc")!==-1?"descending":"ascending"}}compareFunc=null;if(s&&s.compareFunc){if($.type(s.compareFunc)==="function"){compareFunc=s.compareFunc}else if(typeof s.compareFunc==="string"&&window[s.compareFunc]&&typeof window[s.compareFunc]==="function"){compareFunc=window[s.compareFunc]}}curNewExpr={fieldName:colKey,isSorting:true,dir:newDir.startsWith("asc")?"asc":"desc",compareFunc:compareFunc,layout:this.grid.options.key||null};sortingNewExprs=this.grid._getSortingExpressionsManager().addSortingExpression(expr.slice(),curNewExpr,this);this._trigger("internalcolumnsorting",null,{owner:this});sortingNewExprs=this.grid._getSortingExpressionsManager().setFormattersForSortingExprs(sortingNewExprs);if(!apiCall){noCancel=this._trigger(this.events.columnSorting,null,{columnKey:colKey,direction:newDir,owner:this,newExpressions:sortingNewExprs})}this.grid._fireInternalEvent("_sortedColumnsChanging",sortingNewExprs);if(noCancel){s.currentSortDirection=curNewExpr.dir.startsWith("asc")?"ascending":"descending";this._loadingIndicator.show();this._setHeaderAttributes(header,s.currentSortDirection);if(this.options.mode==="single"){for(i=0;i<this.grid.options.columns.length;i++){if(this.options.columnSettings[i]&&this.options.columnSettings[i].columnKey!==colKey){delete this.options.columnSettings[i].currentSortDirection;this._clearSortStyles(this.options.columnSettings[i].columnKey)}}}this.grid.dataSource.settings.sorting.expressions=sortingNewExprs;noCancel=this.grid._trigger(this.grid.events.dataBinding,null,{owner:this.grid,dataSource:this.grid.dataSource});if(this.grid._hasUnboundColumns&&this.options.type==="remote"){this.grid._rebindUnboundColumns=true}if(noCancel){this._saveSortingExpressions();this.grid.element.trigger("iggriduisoftdirty",{owner:this});this._curColKey=colKey;if(this.options.type==="remote"){if(!apiCall){this._shouldFireColumnSorted=true}this.grid.dataSource.dataBind()}else{this.grid.dataSource.sort(this.grid.dataSource.settings.sorting.expressions,s.currentSortDirection);this.grid._renderData();if(!apiCall){this._trigger(this.events.columnSorted,null,{columnKey:colKey,direction:s.currentSortDirection,owner:this,expressions:this.grid.dataSource.settings.sorting.expressions})}}this._curSortDir=s.currentSortDirection;return true}}},sortMultiple:function(exprs){exprs=exprs||this.grid.dataSource.settings.sorting.expressions;var self=this,noCancel,exprsLen=exprs.length,oldExprsLen=this.grid.dataSource.settings.sorting.expressions.length;noCancel=this.grid._trigger(this.grid.events.dataBinding,null,{owner:this.grid,dataSource:this.grid.dataSource});if(noCancel){this.grid.dataSource.settings.sorting.expressions=exprs;this._curColKey=null;this._clearActiveHeader();if(exprsLen){this._curColKey=exprs[exprsLen-1].fieldName}$.each(this.grid.options.columns,function(index,column){var cs,expr,colKey=column.key;cs=self._getColumnSettingByKey(colKey);if(cs){expr=self._findExpressionByColKey(colKey,exprs);if(expr){cs.currentSortDirection=expr.dir;self._applySortStyles(colKey)}else{cs.currentSortDirection=undefined;self._clearSortStyles(colKey)}}});this._saveSortingExpressions();if(this.options.type==="remote"){this.grid.dataSource.dataBind()}else{this.grid.dataSource.sort(exprs);if(this.grid.dataSource.settings.sorting.expressions.length===0&&oldExprsLen>0&&this.grid.dataSource.settings.sorting.defaultFields.length===0){this.grid.dataSource.dataBind()}else{this.grid._renderData()}}}},clearSorting:function(){var i,se=[],exprs=this.grid.dataSource.settings.sorting.expressions;for(i=0;i<exprs.length;i++){se.push(exprs[i].fieldName)}for(i=0;i<se.length;i++){this.unsortColumn(se[i],undefined)}},unsortColumn:function(index,header){var colKey,expr,noCancel=true,s,exprLen,headerId,$th,apiCall=!header;this._activeSortedCol=null;if($.type(index)==="number"){colKey=this.grid.options.columns[index].key}else{colKey=index}headerId=this.grid.id()+"_"+colKey;$th=header||$("#"+headerId);expr=this.grid.dataSource.settings.sorting.expressions;exprLen=expr.length;s=this._getColumnSettingByKey(colKey);if(!s||!apiCall&&!this._checkSortingAllowed(colKey)){return}s.currentSortDirection=undefined;if(!apiCall){noCancel=this._trigger(this.events.columnSorting,null,{columnKey:colKey,direction:s.currentSortDirection,owner:this,expressions:this.grid.dataSource.settings.sorting.expressions})}if(!noCancel||!this._removeExprByKey(colKey,expr)){return}if(!apiCall&&!(this.grid.dataSource.settings.sorting.expressions.length===0&&this.options.type==="local")){noCancel=this.grid._trigger(this.grid.events.dataBinding,null,{owner:this.grid,dataSource:this.grid.dataSource})}if(noCancel){this._curColKey=this._curColKey===colKey?null:this._curColKey;this._clearSortStyles(colKey);this.grid.element.trigger("iggriduisoftdirty",{owner:this});this.grid._fireInternalEvent("_sortedColumnsChanging",expr);$th.removeClass(this.css.sortableColumnHeaderFocus).removeClass(this.css.sortableColumnHeaderActive);this._saveSortingExpressions();if(this.options.type==="remote"){if(!this._loadingIndicator){this._initLoadingIndicator()}this._loadingIndicator.show();if(!apiCall){this._shouldFireColumnSorted=true}this.grid.dataSource.dataBind()}else{if(this.grid.dataSource.settings.sorting.expressions.length===0&&exprLen>0&&this.grid.dataSource.settings.sorting.defaultFields.length===0){this.grid.dataBind()}else{this.grid.dataSource.sort(this.grid.dataSource.settings.sorting.expressions);this.grid._renderData()}if(!apiCall){this._trigger(this.events.columnSorted,null,{columnKey:colKey,direction:s.currentSortDirection,owner:this,expressions:this.grid.dataSource.settings.sorting.expressions})}}this._curSortDir=s.currentSortDirection}},_excludeExpr:function(key){if(this.options.persist&&!this._couldPreserveData()){return}var expr=this.grid.dataSource.settings.sorting.expressions,i;for(i=0;i<expr.length;i++){if(expr[i].fieldName===key){$.ig.removeFromArray(expr,i)}}},_applySortStyles:function(columnKey,ignoreActiveSelection){var prevHeight=null,span,$cells,indicatorContainer,$th,currentColumnSetting,$tbody,hasFixedColumns=this.grid.hasFixedColumns();if(this.grid.options.fixedHeaders){prevHeight=this.grid.headersTable().outerHeight()}$th=$("#"+this.grid.id()+"_"+columnKey);span=$th.find(".ui-iggrid-colindicator");if(span.length===0){span=$("<span></span>").addClass(this.css.sortIndicator)}indicatorContainer=$th.find(".ui-iggrid-indicatorcontainer");if(indicatorContainer.length===0){indicatorContainer=$("<div></div>").appendTo($th).addClass("ui-iggrid-indicatorcontainer")}indicatorContainer.append(span);currentColumnSetting=this._getColumnSettingByKey(columnKey);if(this.options.applySortedColumnCss!==false&&ignoreActiveSelection!==true){if(hasFixedColumns&&this.grid._isFixedElement($th)){$tbody=this.grid.fixedTable().children("tbody")}else{$tbody=this.grid.element.children("tbody")}$cells=this.grid._getCellsByColKey($tbody.find(">tr:not([data-grouprow],[data-summaryrow])"),columnKey)}this._activeSortedCol=null;if(currentColumnSetting&&currentColumnSetting.currentSortDirection){if(currentColumnSetting.currentSortDirection.indexOf("asc")!==-1){span.removeClass(this.css.sortIndicatorDescending).addClass(this.css.sortIndicatorAscending);$th.removeClass(this.css.descendingColumnHeader).addClass(this.css.ascendingColumnHeader);this._setHeaderAttributes($th,"ascending");if(this.options.mode==="single"){$th.siblings("th").removeAttr("aria-sort")}if($cells){this._activeSortedCol={key:currentColumnSetting.columnKey,asc:true};$cells.removeClass(this.css.descendingColumn).addClass(this.css.ascendingColumn)}}else{span.removeClass(this.css.sortIndicatorAscending).addClass(this.css.sortIndicatorDescending);$th.removeClass(this.css.ascendingColumnHeader).addClass(this.css.descendingColumnHeader);this._setHeaderAttributes($th,"descending");if(this.options.mode==="single"){$th.siblings("th").removeAttr("aria-sort")}if($cells){this._activeSortedCol={key:currentColumnSetting.columnKey,asc:false};$cells.removeClass(this.css.ascendingColumn).addClass(this.css.descendingColumn)}}}else{this._removeHeaderAttributes($th);this._clearHeaderCellSortStyles($th)}if(prevHeight!==null&&prevHeight!==this.grid.headersTable().outerHeight()){this.grid._initializeHeights()}},_clearSortStateByColKey:function(key){var s=this._getColumnSettingByKey(key);this._clearSortStyles(key);if(!s){return}s.currentSortDirection=undefined},_clearSortStyles:function(key){if(key===undefined||key===null){return}var hk=this.grid.id()+"_"+key,$cells,i,$tbl,$th,cs;for(i=0;i<this.options.columnSettings.length;i++){cs=this.options.columnSettings[i];if(cs.columnKey===key){if(this.grid._detachedHeaderCells&&this.grid._detachedHeaderCells[key]){$th=this.grid._detachedHeaderCells[key][0]}$th=!$th||!$th.length?$("#"+hk):$th;break}}if(this.options.applySortedColumnCss!==false){$tbl=this.grid.isFixedColumn(key)?$("#"+this.grid.id()+"_fixed"):this.grid.element;$cells=this.grid._getCellsByColKey($tbl,key);$cells.removeClass(this.css.descendingColumn).removeClass(this.css.ascendingColumn)}this._clearHeaderCellSortStyles($th);if(cs&&cs.allowSorting){this._removeHeaderAttributes($th)}else{$th.attr("title","")}},_clearHeaderCellSortStyles:function(spanHeader){var span=spanHeader.find(".ui-iggrid-colindicator");if(span.hasClass("ui-iggrid-colindicator-desc")||span.hasClass("ui-iggrid-colindicator-asc")){span.removeClass(this.css.sortIndicatorDescending).removeClass(this.css.sortIndicatorAscending);spanHeader.removeClass(this.css.ascendingColumnHeader).removeClass(this.css.descendingColumnHeader).removeClass(this.css.sortableColumnHeaderFocus)}},_initDefaultSettings:function(suppressUsrOpts){var settings=[],key,cs=this.options.columnSettings,i,j,k,colIndex=0,defaultExpressions=[],defExpLength,isToSkipGroupBySortingExpr=false,dir,allowSorting,isToCheckUnboundColumns=this.grid._hasUnboundColumns===true&&this.options.type==="remote";if(this.grid.dataSource.settings.sorting.expressions!==null&&this.grid.dataSource.settings.sorting.expressions!==undefined){defaultExpressions=this.grid.dataSource.settings.sorting.expressions}defExpLength=defaultExpressions.length;if(this.grid.options.columns&&this.grid.options.columns.length>0){for(i=0;i<this.grid.options.columns.length;i++){allowSorting=true;if(isToCheckUnboundColumns&&this.grid.getUnboundColumnByKey(this.grid.options.columns[i].key)!==null){allowSorting=false}settings[i]={columnIndex:colIndex,columnKey:this.grid.options.columns[i].key,allowSorting:allowSorting};if(this.grid.options.columns[i].hidden!==true){colIndex++}}}for(i=0;i<cs.length;i++){for(key in cs[i]){if(cs[i].hasOwnProperty(key)&&key!=="columnKey"&&key!=="columnIndex"){if(key==="userSet_currentSortDirection"){if(cs[i].userSet_currentSortDirection==="undefined"||!cs[i].userSet_currentSortDirection){delete cs[i].currentSortDirection}else{cs[i].currentSortDirection=cs[i].userSet_currentSortDirection}}else if(key==="userSet_allowSorting"){cs[i].allowSorting=cs[i][key];delete cs[i][key]}}}}if(settings.length===0&&this.grid.options.autoGenerateColumns&&cs.length>0){for(i=0;i<cs.length;i++){if(!cs[i].columnKey||typeof cs[i].currentSortDirection!=="string"){continue}dir=cs[i].currentSortDirection.startsWith("asc")?"asc":"desc";defaultExpressions.push({fieldName:cs[i].columnKey,isSorting:true,dir:dir})}}else{for(i=0;i<cs.length;i++){for(j=0;j<settings.length;j++){if(settings[j].columnKey!==null&&settings[j].columnKey!==undefined&&cs[i].columnKey!==null&&cs[i].columnKey!==undefined){if(settings[j].columnKey===cs[i].columnKey){break}}else if(settings[j].columnIndex===cs[i].columnIndex){break}}if(j===settings.length){continue}for(key in cs[i]){if(cs[i].hasOwnProperty(key)&&key!=="columnKey"&&key!=="columnIndex"&&!key.startsWith("userSet")){settings[j][key]=cs[i][key];if(!suppressUsrOpts){settings[j]["userSet_"+key]=cs[i][key]}if(key==="currentSortDirection"&&cs[i][key]){if($.type(settings[j].columnKey)!=="number"){isToSkipGroupBySortingExpr=false;if(defExpLength>0){for(k=0;k<defExpLength;k++){if(defaultExpressions[k].fieldName===settings[j].columnKey){if(defaultExpressions[k].isGroupBy===true){isToSkipGroupBySortingExpr=true}else{defaultExpressions.splice(k,1)}break}}}if(isToSkipGroupBySortingExpr===true){continue}defaultExpressions.push({fieldName:settings[j].columnKey,isSorting:true,dir:cs[i][key].startsWith("asc")?"asc":"desc",compareFunc:cs[i].compareFunc})}else{defaultExpressions.push({fieldIndex:settings[j].columnKey,isSorting:true,dir:cs[i][key].startsWith("asc")?"asc":"desc",compareFunc:cs[i].compareFunc})}}}}}}for(i=0;i<settings.length;i++){if(!settings[i].hasOwnProperty("currentSortDirection")){settings[i].userSet_currentSortDirection="undefined"}for(j=0;j<this.grid.dataSource.settings.sorting.expressions.length;j++){if(this.grid.dataSource.settings.sorting.expressions[j].fieldName===settings[i].columnKey){settings[i].currentSortDirection=this.grid.dataSource.settings.sorting.expressions[j].dir}}}this.options.columnSettings=settings;defaultExpressions=this.grid._getSortingExpressionsManager().setFormattersForSortingExprs(defaultExpressions);this.grid.dataSource.settings.sorting.expressions=defaultExpressions;this.grid.dataSource.settings.sorting.defaultFields=defaultExpressions},_clearActiveHeader:function(){if(this._currentActiveHeader){this._currentActiveHeader.removeClass(this.css.sortableColumnHeaderActive).removeClass(this.css.sortableColumnHeaderFocus)}},_initFC:function(){var col,i,cs,initialSorting,featureChooserInstance=this.grid.element.data("igGridFeatureChooser");if(!this._featureChooserInitialized&&featureChooserInstance&&this.renderInFeatureChooser){if(this._featureChooserMenuTogglingHandler){this.grid.element.unbind("iggridfeaturechoosermenutoggling",this._featureChooserMenuTogglingHandler)}this._featureChooserMenuTogglingHandler=$.proxy(this._featureChooserMenuToggling,this);this.grid.element.bind("iggridfeaturechoosermenutoggling",this._featureChooserMenuTogglingHandler);if(featureChooserInstance._isTouchDevice()){for(i=0;i<this.grid.options.columns.length;i++){col=this.grid.options.columns[i];cs=this._getColumnSettingByKey(col.key);if(this._checkSortingAllowed(col.key)){if(featureChooserInstance&&featureChooserInstance._shouldRenderInFeatureChooser(col.key)===true){initialSorting=cs?cs.currentSortDirection:false;if(initialSorting===null){initialSorting=false}featureChooserInstance._renderInFeatureChooser(col.key,{name:"SortingAscending",text:this._getLocaleValue("featureChooserSortAsc"),textHide:this._getLocaleValue("featureChooserSortAsc"),iconClass:this.css.fcSortIndicatorAscending,iconClassOff:this.css.fcSortIndicatorAscending,isSelected:initialSorting&&typeof initialSorting==="string"?initialSorting.toLowerCase().indexOf("asc")>-1:false,method:$.proxy(this._sortAscFromFeatureChooser,this),updateOnClickAll:false,groupName:"toggle",groupOrder:1,order:0,type:"toggle"});featureChooserInstance._renderInFeatureChooser(col.key,{name:"SortingDescending",text:this._getLocaleValue("featureChooserSortDesc"),textHide:this._getLocaleValue("featureChooserSortDesc"),iconClass:this.css.fcSortIndicatorDescending,iconClassOff:this.css.fcSortIndicatorDescending,isSelected:initialSorting&&typeof initialSorting==="string"?initialSorting.toLowerCase().indexOf("desc")>-1:false,method:$.proxy(this._sortDescFromFeatureChooser,this),updateOnClickAll:false,groupName:"toggle",groupOrder:1,order:0,type:"toggle"})}}}}if(this.options.mode!=="single"){for(i=0;i<this.grid.options.columns.length;i++){col=this.grid.options.columns[i];if(this._checkSortingAllowed(col.key)){if(featureChooserInstance._shouldRenderInFeatureChooser(col.key)===true){featureChooserInstance._renderInFeatureChooser(col.key,{name:"MultipleSorting",text:this._getLocaleValue("featureChooserText"),iconClass:this.css.featureChooserModalDialogIcon,method:$.proxy(this.openMultipleSortingDialog,this),groupName:"modaldialog",groupOrder:3,order:2})}}}}this._featureChooserInitialized=true}},_headerCellRendered:function(event,ui){var cs=this._getColumnSettingByKey(ui.columnKey),expr;if(event.target.id!==this.grid.element[0].id){return}if(ui.isMultiColumnHeader===true){return}if(ui.columnKey&&cs){this._headers.push({header:ui.th,index:cs.columnIndex});if(this._checkSortingAllowed(ui.columnKey)!==false){ui.th.addClass(this.css.sortableColumnHeader);if(cs.currentSortDirection===undefined||cs.currentSortDirection===null){ui.th.attr("title",this._getLocaleValue("unsortedColumnTooltip"))}else{ui.th.attr("title",cs.currentSortDirection.startsWith("asc")?this._getLocaleValue("sortedColumnTooltip").replace("${direction}",this._getLocaleValue("ascending")):this._getLocaleValue("sortedColumnTooltip").replace("${direction}",this._getLocaleValue("descending")))}$("<span></span>").appendTo(ui.th).addClass(this.css.sortIndicator);if(cs.currentSortDirection!==undefined){expr=this._findExpressionByColKey(cs.columnKey);if(expr&&!expr.isGroupBy){this._applySortStyles(cs.columnKey)}}}}this._initFC()},_featureChooserMenuToggling:function(event,args){var i,expr,isAsc,hasSorting=false,columnKey=args.columnKey,featureChooserInstance=this.grid.element.data("igGridFeatureChooser"),exprs=this.grid.dataSource.settings.sorting.expressions,exprsLength=exprs.length;if(!args.isVisible){for(i=0;i<exprsLength;i++){expr=exprs[i];if(expr.fieldName===columnKey){hasSorting=true;isAsc=false;if(expr.dir&&expr.dir.toLowerCase().indexOf("asc")>-1){isAsc=true}featureChooserInstance._setSelectedState("SortingDescending",columnKey,!isAsc,false);featureChooserInstance._setSelectedState("SortingAscending",columnKey,isAsc,false)}}if(!hasSorting){featureChooserInstance._setSelectedState("SortingDescending",columnKey,false,false);featureChooserInstance._setSelectedState("SortingAscending",columnKey,false,false)}}},_sortAscFromFeatureChooser:function(event,columnKey,isSelected){var featureChooserInstance=this.grid.element.data("igGridFeatureChooser"),gridId=this.grid.id(),$th=$("#"+gridId+"_"+columnKey);if(!featureChooserInstance){return}featureChooserInstance._setSelectedState("SortingDescending",columnKey,false,false);if(isSelected){this.sortColumn(columnKey,"asc",$th)}else{this.unsortColumn(columnKey,$th)}},_sortDescFromFeatureChooser:function(event,columnKey,isSelected){var featureChooserInstance=this.grid.element.data("igGridFeatureChooser"),gridId=this.grid.id(),$th=$("#"+gridId+"_"+columnKey);featureChooserInstance._setSelectedState("SortingAscending",columnKey,false,false);if(!featureChooserInstance){return}if(isSelected){
this.sortColumn(columnKey,"desc",$th)}else{this.unsortColumn(columnKey,$th)}},_fixedColumnsChanged:function(args){var i,grid=this.grid,stngs=this.options.columnSettings,start=args.start,len=args.length,at=args.at,fixedTable=grid.fixedHeadersTable(),isAttachedSortingHandlers=fixedTable.data("attachedSortingHandlers");if(isAttachedSortingHandlers!==true){fixedTable.data("attachedSortingHandlers",true);fixedTable.delegate("thead th",{click:this._clickHandler,mouseover:this._mouseOverHandler,mouseout:this._mouseOutHandler})}grid._rearrangeArray(stngs,start,len,at);for(i=0;i<stngs.length;i++){stngs[i].columnIndex=i}},_columnsRearranged:function(){this._initDefaultSettings(true)},_columnMap:function(){var self=this,isMultiple=self.options.mode!=="single";return $.map(this.grid.options.columns,function(col){var cs=self._getColumnSettingByKey(col.key),allowSorting=!!(isMultiple&&cs&&cs.allowSorting);return{columnKey:col.key,enabled:allowSorting}})},_findExpressionByColKey:function(key,exprs){exprs=exprs||this.grid.dataSource.settings.sorting.expressions;var i,len=exprs.length,res=null,layout=this.grid.options.key||null;for(i=0;i<len;i++){if(exprs[i].fieldName===key&&(!exprs[i].layout&&!layout||exprs[i].layout===layout)){return exprs[i]}}return res},_dataRendered:function(){var i,cs,expr,col,colKey,gridId=this.grid.element[0].id,ignoreActiveSelection;if(!this._loadingIndicator){this._initLoadingIndicator()}expr=this._sortingExpressions;if(this._shouldFireColumnSorted){this._trigger(this.events.columnSorted,null,{columnKey:this._curColKey,direction:this._curSortDir,owner:this,expressions:this.grid.dataSource.settings.sorting.expressions});this._shouldFireColumnSorted=false}this._loadingIndicator.hide();if(this._curColKey!==undefined&&this._curColKey!==null){this._applySortStyles(this._curColKey)}else if(this.options.persist&&this._restoreSorting&&expr&&expr.length>0){for(i=0;i<expr.length;i++){if(expr[i].isGroupBy){continue}colKey=expr[i].fieldName;cs=this._getColumnSettingByKey(colKey);if(cs){cs.currentSortDirection=expr[i].dir}ignoreActiveSelection=true;col=$("#"+gridId+"_"+colKey);this._curColKey=colKey;if(i===expr.length-1){col.addClass(this.css.sortableColumnHeaderActive);this._currentActiveHeader=col;ignoreActiveSelection=false;this._curColKey=colKey}this._applySortStyles(colKey,ignoreActiveSelection)}this._restoreSorting=false}},_onUIDirty:function(e,args){if(this.options.persist&&this.options.type==="remote"){return}var i,j,exprs=this.grid.dataSource.settings.sorting.expressions,defaultExprs=this.grid.dataSource.settings.sorting.defaultFields,cs=this.options.columnSettings,skip=false;if(args.owner===this||args.owner.element[0].id!==this.element[0].id){return}this._curColKey=null;this._clearUi(true);for(i=0;i<exprs.length;i++){skip=false;for(j=0;j<cs.length;j++){if(exprs[i].isGroupBy===true||cs[j].columnKey===exprs[i].fieldName&&cs[j].userSet_currentSortDirection){skip=true;break}}if(!skip){if(exprs.length>i){$.ig.removeFromArray(exprs,i)}if(defaultExprs.length>i){$.ig.removeFromArray(defaultExprs,i)}}}},_clearUi:function(){var i,header,csd,isMCH=this.grid._isMultiColumnGrid,persist=this.options.persist;for(i=0;this._headers&&i<this._headers.length;i++){csd=this.options.columnSettings[i].userSet_currentSortDirection;if((isMCH||persist)&&this.options.columnSettings[i].columnKey){header=$("#"+this.grid.element[0].id+"_"+this.options.columnSettings[i].columnKey)}else{header=this._headers[i].header}if(!csd||csd==="undefined"){this._clearSortStyles(this.options.columnSettings[i].columnKey);if(this.options.mode!=="single"){delete this.options.columnSettings[i].currentSortDirection;this._excludeExpr(this.options.columnSettings[i].columnKey)}}else{this._applySortStyles(this.options.columnSettings[i].columnKey)}header.removeClass(this.css.sortableColumnHeaderActive).removeClass(this.css.sortableColumnHeaderHover).addClass(this.grid.css.headerClass);if(this._checkSortingAllowed(this.options.columnSettings[i].columnKey)){header.addClass(this.css.sortableColumnHeader)}}},_virtualHorizontalScroll:function(event,args){var start=args.startColIndex,end=args.endColIndex,i,j,cs=this.options.columnSettings,header,ths=this.grid.headersTable().find("thead > tr").first().find("th").not("[ data-skip=true ]"),visibleColumns=this.grid._visibleColumns(),key;for(i=0;i<ths.length;i++){header=ths.eq(i);key=header.attr("id").replace(this.grid.id()+"_","");this._clearSortStyles(key);header.removeClass(this.css.sortableColumnHeaderActive).removeClass(this.css.sortableColumnHeaderHover).addClass(this.grid.css.headerClass).addClass(this.css.sortableColumnHeader)}for(i=start;i<=end;i++){header=ths.eq(i-start);header.data("columnIndex",i);for(j=0;j<cs.length;j++){if(cs[j].currentSortDirection&&cs[j].columnKey===visibleColumns[i].key){this._applySortStyles(cs[j].columnKey)}}}},_columnsCollectionModified:function(event,args){if(args.owner.element.attr("id")!==this.grid.element.attr("id")){return}var i,j,found,colKey,cs,visibleColumns=this.grid._visibleColumns();for(i=0;i<this.options.columnSettings.length;i++){j=0;found=false;for(j=0;j<visibleColumns.length;j++){if(visibleColumns[j].key===this.options.columnSettings[i].columnKey){found=true;colKey=visibleColumns[j].key;break}}if(found){this.options.columnSettings[i].columnIndex=j;cs=this.options.columnSettings[i];if(cs&&cs.currentSortDirection!==undefined&&this.options.applySortedColumnCss!==false){this._applySortStyles(colKey,true)}}}if(this._curColKey){this._applySortStyles(this._curColKey)}$("#"+this.element[0].id+" thead th").removeClass(this.css.sortableColumnHeaderHover)},_detachEvents:function(){if(this._headerCellRenderedHandler){this.grid.element.unbind("iggridheadercellrendered",this._headerCellRenderedHandler)}if(this._virtualHorizontalScrollHandler){this.grid.element.unbind("iggridvirtualhorizontalscroll",this._virtualHorizontalScrollHandler)}if(this._uiDirtyHandler){this.grid.element.unbind("iggriduidirty",this._uiDirtyHandler)}if(this._headerRenderedHandler){this.grid.element.unbind("iggridheaderrendered",this._headerRenderedHandler)}if(this._columnsCollectionModifiedHandler){this.grid.element.unbind("iggridcolumnscollectionmodified",this._columnsCollectionModifiedHandler)}if(this._columnsRearangedHandler){this.grid.element.unbind("iggrid_columnsmoved",this._columnsRearangedHandler)}if(this._featureChooserMenuTogglingHandler){this.grid.element.unbind("iggridfeaturechoosermenutoggling",this._featureChooserMenuTogglingHandler)}},destroy:function(){var i,a,fc,header,span,text,modalDialog=this._getModalDialog();if(!this.grid){return}$("#"+this.element[0].id+" thead th").unbind("dragstart",this._dragStartHandler);$("#"+this.element[0].id+"_headers thead th").unbind("dragstart",this._dragStartHandler);$(document).undelegate("#"+this.element[0].id+"_headers thead th",{click:this._clickHandler,mouseover:this._mouseOverHandler,mouseout:this._mouseOutHandler});$("#"+this.element[0].id).undelegate("thead th",{click:this._clickHandler,mouseover:this._mouseOverHandler,mouseout:this._mouseOutHandler});$("#"+this.element[0].id).undelegate("thead th",{keydown:this._keyDownHandler,focus:this._focusHandler,blur:this._blurHandler});$(document).undelegate("#"+this.element[0].id+"_headers thead th",{keydown:this._keyDownHandler,focus:this._focusHandler,blur:this._blurHandler});this._detachEvents();delete this._blurHandler;delete this._clickHandler;delete this._headerCellRenderedHandler;delete this._focusHandler;delete this._keyDownHandler;delete this._mouseOutHandler;delete this._mouseOverHandler;delete this._dragStartHandler;delete this._uiDirtyHandler;delete this._virtualHorizontalScrollHandler;delete this._headerRenderedHandler;delete this._columnsRearangedHandler;this.grid.element.find(".ui-iggrid-colasc").removeClass("ui-iggrid-colasc ui-state-highlight");this.grid.element.find(".ui-iggrid-coldesc").removeClass("ui-iggrid-coldesc ui-state-highlight");this._clearUi(true);for(i=0;this._headers&&i<this._headers.length;i++){header=this._headers[i].header;header.removeClass("ui-iggrid-sortableheader ui-state-default"+" ui-state-active ui-state-hover ui-state-focus");header.attr("title","");span=header.find("a span");text=span.text();a=header.find("a:not([ th-remove-focus ])");$("<span>"+text+"</span>").appendTo(header).addClass("ui-iggrid-headertext");a.remove()}fc=this.grid.element.data("igGridFeatureChooser");if(fc&&this.renderInFeatureChooser){fc._removeFeature("SortingAscending");fc._removeFeature("SortingDescending");fc._removeFeature("MultipleSorting")}this._headers=null;if(this._loadingIndicator){delete this._loadingIndicator}modalDialog[this.options.dialogWidget]("getCaptionButtonContainer");modalDialog.remove();this._superApply(arguments);return this},_renderMultipleSortingDialog:function(){var $buttonOK,containment,self=this,o=this.options,modalDialogId=this.grid.element[0].id+"_multiplesorting_modalDialog",$captionButtonContainer,modalDialog;if(this.options.sortingDialogContainment==="owner"){containment=this.grid.container()}else{containment="window"}$("#"+modalDialogId).remove();modalDialog=$("<div></div>").appendTo(this.grid._rootContainer()).attr("id",modalDialogId);modalDialog[this.options.dialogWidget]({containment:containment,locale:{buttonApplyText:this._getLocaleValue("modalDialogButtonApplyText"),buttonCancelText:this._getLocaleValue("modalDialogButtonCancelText"),modalDialogCaptionText:this._getLocaleValue("modalDialogCaptionText")},renderFooterButtons:!o.modalDialogSortOnClick,modalDialogWidth:o.modalDialogWidth,modalDialogHeight:o.modalDialogHeight,animationDuration:o.modalDialogAnimationDuration,gridContainer:this.grid.container(),modalDialogOpening:$.proxy(this._onDialogOpening,this),modalDialogMoving:$.proxy(this._onDialogMoving,this),modalDialogClosing:$.proxy(this._onDialogClosing,this),modalDialogClosed:$.proxy(this._onDialogClosed,this)});if(o.modalDialogSortOnClick){$captionButtonContainer=modalDialog[this.options.dialogWidget]("getCaptionButtonContainer");$("<span></span>").addClass("ui-icon ui-icon-closethick").appendTo($("<a></a>").appendTo($captionButtonContainer).attr("title",this._getLocaleValue("columnChooserCloseButtonTooltip")).attr("href","#").attr("role","button").addClass("ui-dialog-titlebar-close ui-corner-all").bind("click.hiding",function(event){modalDialog[self.options.dialogWidget]("closeModalDialog",true);event.preventDefault();event.stopPropagation();return false}))}else{$captionButtonContainer=modalDialog[this.options.dialogWidget]("getCaptionButtonContainer");$buttonOK=$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog_footer_buttonok");$buttonOK.bind("igbuttonclick",function(e){self._multiplesortingDialogButtonOKClick(e);e.preventDefault()})}},openMultipleSortingDialog:function(){var modalDialog=$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog");modalDialog[this.options.dialogWidget]("openModalDialog")},closeMultipleSortingDialog:function(){var modalDialog=$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog");modalDialog[this.options.dialogWidget]("closeModalDialog")},_onDialogOpening:function(e,args){var noCancel=this._trigger(this.events.modalDialogOpening,e,{modalDialogElement:args.modalDialog,owner:this});if(noCancel){this._tempExpr=this.grid.dataSource.settings.sorting.expressions.slice(0);this.renderMultipleSortingDialogContent(true);this._trigger(this.events.modalDialogOpened,e,{modalDialogElement:args.modalDialog,owner:this})}return noCancel},_onDialogMoving:function(e,ui){this._trigger(this.events.modalDialogMoving,e,{modalDialogElement:e.target,owner:this,originalPosition:ui.originalPosition,position:ui.position})},_onDialogClosing:function(e,args){return this._trigger(this.events.modalDialogClosing,e,{modalDialogElement:args.modalDialog,owner:this})},_onDialogClosed:function(e,args){this._trigger(this.events.modalDialogClosed,e,{modalDialogElement:args.modalDialog,owner:this})},renderMultipleSortingDialogContent:function(isToCallEvents){var $content,$sortedColumns,$unsortedColumns,i,noCancel=true,self=this,tempExpr,grid=this.grid,columns=grid.options.columns,css=this.css,modalDialog=$("#"+grid.element[0].id+"_multiplesorting_modalDialog");if(isToCallEvents){noCancel=this._trigger(this.events.modalDialogContentsRendering,null,{modalDialogElement:modalDialog,owner:this})}if(noCancel){this.removeDialogClearButton();$content=modalDialog[this.options.dialogWidget]("getContent");$content.empty();$sortedColumns=$("<div></div>").attr("id",grid.element[0].id+"_multiplesorting_modalDialog_sortedcolumns").addClass(css.dialogSortedColumns).appendTo($content);$unsortedColumns=$("<div></div>").attr("id",grid.element[0].id+"_multiplesorting_modalDialog_unsortedcolumns").addClass(css.dialogUnsortedColumns).appendTo($content);$("<ul></ul>").addClass(css.dialogSortedColumnsList).appendTo($sortedColumns);$("<ul></ul>").addClass(css.dialogUnsortedColumnsList).appendTo($unsortedColumns);tempExpr=self._tempExpr||[];tempExpr.forEach(function(se){var key=se.fieldName,cs=self._getColumnSettingByKey(key);if(!cs||self._checkSortingAllowed(key)===false){return}self._renderDialogSortedColumn(grid.columnByKey(key),cs.columnIndex,se.dir)});$.each(columns,function(columnIndex,column){var cs,direction,key=column.key;cs=self._getColumnSettingByKey(key);if(!cs||self._checkSortingAllowed(key)===false){return true}for(i=0;i<tempExpr.length;i++){if(tempExpr[i].fieldName===key){return true}}direction=cs.currentSortDirection||cs.firstSortDirection||self.options.firstSortDirection;self._renderDialogUnsortedColumn(column,cs.columnIndex,direction)});if(isToCallEvents){this._trigger(this.events.modalDialogContentsRendered,null,{modalDialogElement:modalDialog,owner:this})}if(this._isToRenderButtonClearAll()){this._renderDialogButtonClearAll()}}},_renderDialogSortedColumn:function(column,columnIndex,direction){var self=this,$li,css=this.css,$buttonUnsort,liHTML,o=this.options,key=column.key,buttonAscDescId=this.grid.element[0].id+"_"+key+"_multiplesorting_modalDialog_sortedcolumns_buttonascdesc",buttonUnsortId=this.grid.element[0].id+"_"+key+"_multiplesorting_modalDialog_sortedcolumns_buttonunsort",$ul=$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog_sortedcolumns ul");$ul.css("width");$li=$("<li  tabIndex='0'></li>").attr("id",self.grid.element[0].id+"_"+key+"_multiplesorting_sorted_li").addClass(css.dialogSortedColumnsItem);$li.appendTo($ul);if(columnIndex!==null&&columnIndex!==undefined){$li.attr("li-order",columnIndex)}liHTML="<span id='"+buttonAscDescId+"' class='"+css.dialogButtonAsc+"' role='button' title='"+this._getLocaleValue("modalDialogCaptionButtonDesc")+"' data-localeid='modalDialogCaptionButtonDesc' data-localeattr='title'>"+"\t<span class='"+css.dialogButtonAscIcon+"'></span>"+"</span>"+"<span class='"+css.dialogSortedColumnTextContainer+"'>"+column.headerText+"</span>"+"<button type='button' id='"+buttonUnsortId+"' class='"+css.dialogButtonUnsort+"' role='button' data-localeid='modalDialogCaptionButtonUnsort' "+"data-localeattr='title' title='"+this._getLocaleValue("modalDialogCaptionButtonUnsort")+"' >"+"\t<span class='"+css.dialogButtonUnsortContainer+"'></span>"+"\t<span class='ui-button-text' data-localeid='modalDialogCaptionButtonUnsort'>"+this._getLocaleValue("modalDialogCaptionButtonUnsort")+"</span>"+"</button>";$li.bind({click:function(e){self._curColKey=key;self._dialogButtonAscDescClick(key);if(self._isToRenderButtonClearAll()){self._renderDialogButtonClearAll()}else{self.removeDialogClearButton()}e.preventDefault();e.stopPropagation()}});$li.html(liHTML);$buttonUnsort=$("#"+buttonUnsortId);if(direction!==undefined){if(direction.indexOf("asc")!==-1){self._setDialogButtonAscDesc(true,key)}else{self._setDialogButtonAscDesc(false,key)}}else{self._setDialogButtonAscDesc(true,key)}$buttonUnsort.bind({keydown:function(e){if(e.keyCode===$.ui.keyCode.ENTER||e.keyCode===$.ui.keyCode.SPACE){e.target.click();e.preventDefault();e.stopPropagation()}},click:function(e){var noCancel,gridId=self.grid.element[0].id,modalDialog=$("#"+gridId+"_multiplesorting_modalDialog");noCancel=self._trigger(self.events.modalDialogButtonUnsortClick,e,{modalDialogElement:modalDialog,owner:self,columnKey:key});if(noCancel){$li.remove();if(o.modalDialogSortOnClick===true){self.unsortColumn(key,$("#"+gridId+"_"+key))}else{self._removeExprByKey(key,self._tempExpr)}self._renderDialogUnsortedColumn(column,columnIndex,direction);if(self._isToRenderButtonClearAll()){self._renderDialogButtonClearAll()}else{self.removeDialogClearButton()}}e.preventDefault();e.stopPropagation()},mouseover:function(){if(!$(this).hasClass(css.dialogButtonsHover)){$(this).addClass(css.dialogButtonsHover)}},mouseout:function(){if($(this).hasClass(css.dialogButtonsHover)){$(this).removeClass(css.dialogButtonsHover)}}});return $li},_dialogButtonAscDescClick:function(colKey){var o=this.options,noCancel,modalDialog=$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog"),$buttonAscDesc=$("#"+this.grid.element[0].id+"_"+colKey+"_multiplesorting_modalDialog_sortedcolumns_buttonascdesc"),isAsc=$buttonAscDesc.data("isAsc");noCancel=this._trigger(this.events.modalDialogSortingChanged,null,{modalDialogElement:modalDialog,owner:this,columnKey:colKey,isAsc:!isAsc});if(noCancel){this._curColKey=colKey;if(this._isToRenderButtonClearAll()){this._renderDialogButtonClearAll()}else{this.removeDialogClearButton()}if(isAsc===true){if(o.modalDialogSortOnClick===true){this.sortColumn(colKey,"descending",this._getHeaderCellByIdentifier(colKey))}else{this._sortTempExprs(colKey,"desc")}this._setDialogButtonAscDesc(false,colKey)}else{if(o.modalDialogSortOnClick===true){this.sortColumn(colKey,"ascending",this._getHeaderCellByIdentifier(colKey))}else{this._sortTempExprs(colKey,"asc")}this._setDialogButtonAscDesc(true,colKey)}}},_setDialogButtonAscDesc:function(isAsc,colKey){var css=this.css,buttonAscDescId=this.grid.element[0].id+"_"+colKey+"_multiplesorting_modalDialog_sortedcolumns_buttonascdesc",$buttonAscDesc=$("#"+buttonAscDescId),$spanIcon=$buttonAscDesc.find("span:eq(0)");$buttonAscDesc.data("isAsc",isAsc);if(isAsc===true){$buttonAscDesc.attr({title:this._getLocaleValue("modalDialogCaptionButtonDesc"),"data-localeid":"modalDialogCaptionButtonDesc","data-localeattr":"title"}).removeClass(css.dialogButtonDesc).addClass(css.dialogButtonAsc);$spanIcon.removeClass(css.dialogButtonDescIcon).addClass(css.dialogButtonAscIcon)}else{$buttonAscDesc.attr({title:this._getLocaleValue("modalDialogCaptionButtonAsc"),"data-localeid":"modalDialogCaptionButtonAsc","data-localeattr":"title"}).removeClass(css.dialogButtonAsc).addClass(css.dialogButtonDesc);$spanIcon.removeClass(css.dialogButtonAscIcon).addClass(css.dialogButtonDescIcon)}},_removeExprByKey:function(colKey,exprs){var i,len=exprs.length;for(i=0;i<len;i++){if(exprs[i].fieldName===colKey){exprs.splice(i,1);return true}}return false},_sortTempExprs:function(colKey,dir){var i,exprs=this._tempExpr,expr={fieldName:colKey,isSorting:true,dir:dir};for(i=0;i<exprs.length;i++){if(exprs[i].fieldName===colKey){exprs[i]=expr;return}}exprs.push(expr)},_renderDialogUnsortedColumn:function(column,columnIndex,direction){var self=this,$li,$a,key=column.key,o=this.options,css=this.css,$ul=$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog_unsortedcolumns ul");$ul.css("width");$li=$("<li></li>").attr("id",self.grid.element[0].id+"_"+key+"_multiplesorting_unsorted_li").addClass(css.dialogUnsortedColumnsItem).append("<span class='"+css.dialogUnsortedColumnsSortByButton+"'><a href='#'></a></span> <span class='"+css.dialogItemText+"'>"+column.headerText+"</span>");this._insertColumnModalDialog($ul,$li,columnIndex);if(columnIndex!==null&&columnIndex!==undefined){$li.attr("li-order",columnIndex)}$a=$li.find("a:first");$a.addClass(css.modalDialogSortByColumn);$a.attr({"data-localeid":"modalDialogSortByButtonText"}).html(this._getLocaleValue("modalDialogSortByButtonText"));$li.bind({keydown:function(e){if(event.keyCode===$.ui.keyCode.ENTER||event.keyCode===$.ui.keyCode.SPACE){$li.click();e.preventDefault();e.stopPropagation()}},click:function(e){var noCancel,modalDialog=$("#"+self.grid.element[0].id+"_multiplesorting_modalDialog");noCancel=self._trigger(self.events.modalDialogSortClick,e,{modalDialogElement:modalDialog,owner:self,columnKey:key});if(noCancel){$li.remove();self._renderDialogSortedColumn(column,columnIndex,direction);self._sortTempExprs(column.key,direction);if(o.modalDialogSortOnClick){self.sortColumn(key,null,self._getHeaderCellByIdentifier(key))}else{if(self._isToRenderButtonClearAll()){self._renderDialogButtonClearAll()}else{self.removeDialogClearButton()}}}e.preventDefault();e.stopPropagation()}});return $li},_isToRenderButtonClearAll:function(){var i,j,cs,columnKey,expr=this._tempExpr;for(i=0;i<this.options.columnSettings.length;i++){cs=this.options.columnSettings[i];if(!this._checkSortingAllowed(cs.columnKey)){continue}columnKey=cs.columnKey;for(j=0;j<expr.length;j++){if(expr[j].fieldName===columnKey){if(cs.userSet_currentSortDirection!==expr[j].dir){return true}break}}if(j===expr.length&&cs.userSet_currentSortDirection!=="undefined"&&cs.userSet_currentSortDirection){return true}}return false},_getDialogClearAllButton:function(){return $("#"+this.grid.element[0].id+"_sorting_modalDialog_reset_button")},_getModalDialog:function(){return $("#"+this.grid.element[0].id+"_multiplesorting_modalDialog")},removeDialogClearButton:function(){this._getDialogClearAllButton().remove()},_onDialogButtonClearAllClick:function(e){var noCancel,i,cs=this.options.columnSettings;noCancel=this._trigger(this.events.modalDialogButtonResetClick,e,{modalDialogElement:$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog"),owner:this});if(noCancel){this._tempExpr=[];for(i=0;i<cs.length;i++){if(cs[i].userSet_currentSortDirection&&cs[i].userSet_currentSortDirection!=="undefined"&&this._checkSortingAllowed(cs[i].columnKey)!==false){this._tempExpr.push({fieldName:cs[i].columnKey,isSorting:true,dir:cs[i].userSet_currentSortDirection})}}this.renderMultipleSortingDialogContent(false);this.removeDialogClearButton()}},_renderDialogButtonClearAll:function(){if(this.options.modalDialogSortOnClick===true){return}var resetButtonId=this.grid.element[0].id+"_sorting_modalDialog_reset_button",modalDialog=$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog"),$captionButtonContainer,$resetButton;if($("#"+resetButtonId).length===0){$captionButtonContainer=modalDialog[this.options.dialogWidget]("getCaptionButtonContainer");$resetButton=$("<button type='button'></button>").attr("id",resetButtonId).appendTo($captionButtonContainer);$resetButton.igButton({labelText:this._getLocaleValue("modalDialogResetButton"),click:$.proxy(this._onDialogButtonClearAllClick,this)})}},_multiplesortingDialogButtonOKClick:function(e){var noCancel,exprs=this.grid._getSortingExpressionsManager().setFormattersForSortingExprs(this._tempExpr),modalDialog=$("#"+this.grid.element[0].id+"_multiplesorting_modalDialog");noCancel=this._trigger(this.events.modalDialogButtonApplyClick,e,{modalDialogElement:modalDialog,owner:this,columnsToSort:this._tempExpr});if(noCancel){this.sortMultiple(exprs);modalDialog[this.options.dialogWidget]("closeModalDialog")}},_insertColumnModalDialog:function($ul,$li,pos){var i,$currLi,currPos,listItems=$ul.find("li"),listItemsLength=listItems.length;if(listItemsLength===0||pos===null||pos===undefined){$li.appendTo($ul);return}for(i=0;i<listItemsLength;i++){$currLi=$(listItems[i]);currPos=$currLi.attr("li-order");if(currPos>=pos){$li.insertBefore($currLi);break}}if(i===listItemsLength){$li.appendTo($ul)}},_getColumnSettingByKey:function(key){var i,colSettings=this.options.columnSettings,len=colSettings.length;for(i=0;i<len;i++){if(colSettings[i].columnKey===key){return colSettings[i]}}},_headerRendered:function(event,ui){if(ui.owner.element.attr("id")!==this.grid.element.attr("id")){return}if(this.grid.element.data("igGridResizing")){this._resizing=this.grid.element.data("igGridResizing")}if(!this._columnFixing&&this.grid.element.data("igGridColumnFixing")){this._columnFixing=this.grid.element.data("igGridColumnFixing")}if(this.options.mode!=="single"){this._renderMultipleSortingDialog()}},_saveSortingExpressions:function(){var grid=this.grid;if(this.options.persist){var se;se=$.grep(this.grid.dataSource.settings.sorting.expressions,function(s){var col=grid.columnByKey(s.fieldName);return!col||col.unbound!==true});this.grid._savePersistenceData(se,"sorting",this.grid.element[0].id);this._sortingExpressions=se;this._restoreSorting=false}},_preserveSorting:function(){var grid=this.grid,arr,gbArr=[],se=grid._getPersistenceData("sorting",grid.element[0].id),topmostEl,gb,i,layout=grid.options.key,indToRemove;if(se){topmostEl=this.element.closest(".ui-iggrid-root");this._restoreSorting=true;if(se!==this._sortingExpressions){this._sortingExpressions=se}if(topmostEl.length&&topmostEl.attr("id")!==grid.id()){gb=topmostEl.data("igGridGroupBy");if(gb){if(grid.element.data("igGridGroupBy")){arr=grid.dataSource.settings.sorting.defaultFields;for(i=0;i<arr.length;i++){if(arr[i].layout===layout){if(arr[i].isGroupBy){gbArr.push(arr[i]);continue}break}}}indToRemove=-1;for(i=0;i<se.length;i++){if(se[i].isGroupBy){indToRemove=i}else{break}}if(indToRemove>-1){$.ig.removeFromArray(se,0,indToRemove)}for(i=0;i<gbArr.length;i++){se.unshift(gbArr[i])}}}se=grid._getSortingExpressionsManager().setFormattersForSortingExprs(se);grid.dataSource.settings.sorting.expressions=se;grid.dataSource.settings.sorting.defaultFields=se}},_applyActiveSortCellStyle:function(data,col){var expressionExists=false;$(this.grid.dataSource.settings.sorting.expressions).each(function(){if(this.fieldName===col){expressionExists=true;return false}});if(this._activeSortedCol&&expressionExists&&col===this._activeSortedCol.key){return this._activeSortedCol.asc?this.css.ascendingColumn:this.css.descendingColumn}return""},_couldPreserveData:function(){return!this.options.persist||this.grid.dataSource.settings.sorting.expressions!==this.grid._getPersistenceData("sorting",this.grid.element[0].id)},_injectGrid:function(gridInstance,isRebind){var i,cs,col,restoreSortingExpr,topmostGrid,semgr;this.grid=gridInstance;semgr=this.grid._getSortingExpressionsManager();this._detachEvents();if(this.options.type===null){this.options.type=this.grid._inferOpType()}if(this.options.persist&&this.options.type==="remote"){topmostGrid=this.element.closest(".ui-iggrid-root").data("igGrid");if(topmostGrid&&topmostGrid.element.attr("id")!==this.grid.element[0].id&&topmostGrid.options.initialDataBindDepth===-1){this.options.persist=false}}if(this.options.type){this.grid.dataSource.settings.sorting.type=this.options.type}else{this.grid.dataSource.settings.sorting.type="remote"}this.grid.dataSource.settings.sorting.caseSensitive=this.options.caseSensitive;this.grid.dataSource.settings.sorting.defaultFields=semgr.setFormattersForSortingExprs(this.grid.dataSource.settings.sorting.expressions);this.grid.dataSource.settings.sorting.enabled=true;this.grid.dataSource.settings.sorting.sortUrlKey=this.options.sortUrlKey;this.grid.dataSource.settings.sorting.sortUrlAscValueKey=this.options.sortUrlKeyAscValue;this.grid.dataSource.settings.sorting.sortUrlDescValueKey=this.options.sortUrlKeyDescValue;if($.type(this.options.customSortFunction)==="function"){this.grid.dataSource.settings.sorting.customFunc=this.options.customSortFunction}else if(typeof this.options.customSortFunction==="string"){if(window[this.options.customSortFunction]&&typeof window[this.options.customSortFunction]==="function"){this.grid.dataSource.settings.sorting.customFunc=window[this.options.customSortFunction]}}this._headerCellRenderedHandler=$.proxy(this._headerCellRendered,this);this._columnsCollectionModifiedHandler=$.proxy(this._columnsCollectionModified,this);this._uiDirtyHandler=$.proxy(this._onUIDirty,this);this._headerRenderedHandler=$.proxy(this._headerRendered,this);this._columnsRearangedHandler=$.proxy(this._columnsRearranged,this);this.grid.element.bind("iggridheadercellrendered",this._headerCellRenderedHandler);this._virtualHorizontalScrollHandler=$.proxy(this._virtualHorizontalScroll,this);this.grid.element.bind("iggridvirtualhorizontalscroll",this._virtualHorizontalScrollHandler);this.grid.element.bind("iggriduidirty",this._uiDirtyHandler);this.grid.element.bind("iggridcolumnscollectionmodified",this._columnsCollectionModifiedHandler);this.grid.element.bind("iggridheaderrendered",this._headerRenderedHandler);this.grid.element.bind("iggrid_columnsmoved",this._columnsRearangedHandler);if(this.options.persist&&this.grid._hasUnboundColumns){cs=this.options.columnSettings;for(i=0;i<cs.length;i++){if(cs[i].columnKey&&cs[i].currentSortDirection){col=this.grid.columnByKey(cs[i].columnKey);if(col&&col.unbound===true){delete cs[i].currentSortDirection}}}}this._initDefaultSettings();restoreSortingExpr=null;if(this.options.persist&&this.grid.element.data("igGridGroupBy")&&this.options.mode!=="single"){if(this.grid.element.data("igGridGroupBy")._getSortingExpressions()===this.grid.dataSource.settings.sorting.expressions){restoreSortingExpr=this.grid.dataSource.settings.sorting.expressions.slice(0)}}this._clearUi();if(restoreSortingExpr){this.grid.dataSource.settings.sorting.expressions=semgr.setFormattersForSortingExprs(restoreSortingExpr);this._saveSortingExpressions()}this._currentActiveHeader=null;this._curColKey=null;if(this.options.persist){this._preserveSorting()}if(!isRebind&&!this._cellStyleSubscriberAdded&&(this.grid.options.rowVirtualization||this.grid.options.virtualization)){this._cellStyleSubscriberAdded=true;this.grid._cellStyleSubscribers.push($.proxy(this._applyActiveSortCellStyle,this))}}});$.extend($.ui.igGridSorting,{version:"21.2.12"});return $});