/*!@license
* Infragistics.Web.ClientUI Outlook GroupBy feature 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
*	jquery.ui.mouse.js
*	jquery.ui.draggable.js
*	jquery.ui.droppable.js
*	infragistics.ui.widget.js
*	infragistics.ui.grid.framework.js
*	infragistics.ui.grid.shared.js
*	infragistics.ui.grid.featurechooser.js
*/
(function(factory){if(typeof define==="function"&&define.amd){define(["./infragistics.ui.grid.featurechooser","./infragistics.ui.tree"],factory)}else{return factory(jQuery)}})(function($){"use strict";$.widget("ui.igGridGroupBy",$.ui.igWidget,{css:{dragMarkup:"ui-iggrid-dragMarkup",groupByArea:"ui-iggrid-groupbyarea",groupByAreaText:"ui-iggrid-groupbyareatext",groupedRow:"ui-iggrid-groupedrow",summaryRow:"ui-iggrid-summaryrow",expandHeaderCellGroupBy:"ui-iggrid-header ui-widget-header",groupByExpandCellExpanded:"ui-icon ui-iggrid-expandbutton ui-iggrid-expandbuttonexpanded ui-icon-minus",groupBySummaryIcon:"ui-icon ui-icon-calculator ui-iggrid-groupsummary-icon",groupByExpandCellCollapsed:"ui-icon ui-iggrid-expandbutton ui-icon-plus",groupByAreaDropHover:"ui-iggrid-groupbyareahover",groupByExpandColumn:"ui-iggrid-expandcolumn",groupBySummaryColumn:"ui-iggrid-summarycolumn",groupBySummaryIconColumn:"ui-iggrid-summaryiconcolumn",groupBySummaryEmptyCellColumn:"ui-iggrid-summaryemptycellcolumn",nonGroupRowEmptyCell:"ui-iggrid-nongrouprowemptycell",groupedColumnLabel:"ui-iggrid-groupedcolumnlabel ui-state-default",groupedColumnLabelText:"ui-iggrid-groupedcolumnlabeltext",groupByRemoveButton:"ui-icon ui-icon-circle-close ui-iggrid-groupbyremovebutton",groupedColumnLabelRightEdgeEnd:"ui-iggrid-groupbylabelrightedgeend",groupedColumnLabelRightEdge:"ui-iggrid-groupbylabelrightedge",groupedColumnLayoutLabel:"ui-iggrid-groupbylayoutlabel",headerExtraCell:"ui-iggrid-expandheadercellgb",footerExtraCell:"ui-widget-content ui-iggrid-footerextracell",featureChooserIconClass:"ui-icon ui-iggrid-icon-groupby",dialogGroupedColumns:"ui-iggrid-groupby-dialog-groupedcolumns",dialogUnroupedColumns:"ui-iggrid-groupby-dialog-ungroupedcolumns",dialogGroupedItem:"ui-widget-content",dialogUngroupedItem:"ui-widget-content",dialogUngroupedColumnsGroupByButton:"ui-iggrid-dialog-groupby-button",dialogUngroupedColumnsText:"ui-iggrid-dialog-text",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",dialogButtonUngroup:"ui-iggrid-dialog-groupedbuttons ui-button ui-widget ui-state-default ui-corner-all ui-button-icon-only ui-igbutton ui-widget-content ui-igbutton-remove",dialogButtonUngroupContainer:"ui-button-icon-primary ui-icon ui-icon-circle-close",dialogGroupedColumnTextContainer:"ui-iggrid-dialog-text",dialogListGroupedColumns:"ui-iggrid-dialog-list-groupedcolumns",dialogListUngroupedColumns:"ui-iggrid-dialog-list-ungroupedcolumns",dialogLayoutsDDButton:"ui-icon ui-icon-triangle-1-s ui-iggrid-dialog-layouts-dd-button",dropDownLayoutsContainer:"ui-iggrid-featurechooser-dropdown-dialog ui-widget ui-widget-content ui-corner-all",dialogLayoutsDDField:"ui-iggrid-dialog-layouts-dd-field",dialogLayoutsDD:"ui-iggrid-dialog-layouts-dd ui-widget-content ui-corner-all ig-combo-icon-container",modalDialogTreeContainer:"ui-iggrid-groupby-dialog-tree",modalDialogLayoutsContainer:"ui-iggrid-groupby-dialog-layoutscontainer",dialogButtonsHover:"ui-state-hover",groupByLastEmptyCell:"ui-iggrid-last-emptycell"},renderInFeatureChooser:false,options:{groupByAreaVisibility:"top",initialExpand:true,pagingMode:"allRecords",expansionIndicatorVisibility:true,groupByLabelWidth:null,labelDragHelperOpacity:.5,indentation:30,defaultSortingDirection:"asc",groupedColumns:[{key:null,dir:"asc",layout:null,col:null}],resultResponseKey:null,groupedRowTextTemplate:"${key}: ${val} (${count})",type:null,groupByUrlKey:null,groupByUrlKeyAscValue:null,groupByUrlKeyDescValue:null,summarySettings:{multiSummaryDelimiter:",",summaryFormat:"#.00"},columnSettings:[{allowGrouping:true,isGroupBy:false,compareFunc:null,groupComparerFunction:null,groupLabelFormatter:null,dir:"asc",summaries:[{summaryFunction:"avg",text:null,customSummary:null}],groupSummaries:[{summaryFunction:null,label:"",summaryTemplate:"{label}{result}",format:null}]}],expandTooltip:undefined,collapseTooltip:undefined,removeButtonTooltip:undefined,modalDialogGroupByButtonText:undefined,modalDialogCaptionButtonDesc:undefined,modalDialogCaptionButtonAsc:undefined,modalDialogCaptionButtonUngroup:undefined,modalDialogCaptionText:undefined,modalDialogDropDownLabel:undefined,modalDialogRootLevelHierarchicalGrid:undefined,modalDialogDropDownButtonCaption:undefined,modalDialogClearAllButtonLabel:undefined,emptyGroupByAreaContentSelectColumnsCaption:undefined,modalDialogButtonApplyText:undefined,modalDialogButtonCancelText:undefined,locale:{emptyGroupByAreaContent:undefined,emptyGroupByAreaContentSelectColumns:undefined,emptyGroupByAreaContentSelectColumnsCaption:undefined,expandTooltip:undefined,collapseTooltip:undefined,removeButtonTooltip:undefined,modalDialogCaptionButtonDesc:undefined,modalDialogCaptionButtonAsc:undefined,modalDialogCaptionButtonUngroup:undefined,modalDialogGroupByButtonText:undefined,modalDialogCaptionText:undefined,modalDialogDropDownLabel:undefined,modalDialogClearAllButtonLabel:undefined,modalDialogRootLevelHierarchicalGrid:undefined,modalDialogDropDownButtonCaption:undefined,modalDialogButtonApplyText:undefined,modalDialogButtonCancelText:undefined,summaryRowTitle:undefined,summaryIconTitle:undefined},modalDialogGroupByOnClick:false,modalDialogDropDownWidth:200,modalDialogDropDownAreaWidth:null,modalDialogAnimationDuration:200,modalDialogWidth:400,modalDialogHeight:"",useGridColumnFormatter:true,persist:true,groupByDialogContainment:"owner",dialogWidget:"igGridModalDialog",inherit:false,groupSummaries:[{summaryFunction:"",label:"",summaryTemplate:"{label}{value}",format:null}],groupSummariesPosition:"bottom"},events:{groupedColumnsChanging:"groupedColumnsChanging",groupedColumnsChanged:"groupedColumnsChanged",modalDialogMoving:"modalDialogMoving",modalDialogClosing:"modalDialogClosing",modalDialogClosed:"modalDialogClosed",modalDialogOpening:"modalDialogOpening",modalDialogOpened:"modalDialogOpened",modalDialogContentsRendering:"modalDialogContentsRendering",modalDialogContentsRendered:"modalDialogContentsRendered",modalDialogButtonApplyClick:"modalDialogButtonApplyClick",modalDialogButtonResetClick:"modalDialogButtonResetClick",modalDialogGroupingColumn:"modalDialogGroupingColumn",modalDialogGroupColumn:"modalDialogGroupColumn",modalDialogUngroupingColumn:"modalDialogUngroupingColumn",modalDialogUngroupColumn:"modalDialogUngroupColumn",modalDialogSortGroupedColumn:"modalDialogSortGroupedColumn"},_create:function(){this._orderedGroupedCols=[]},_createWidget:function(){this.options.columnSettings=[];this.options.groupedColumns=[];this.options.groupSummaries=false;this._tempSortingExpr=[];this._tempGroupedColumns=[];this._tempOrderedGroupedCols=[];this._tempOptions={};this._currentTreeLayer=null;this._isInitFC=false;this._modalSelectedLayout=null;$.Widget.prototype._createWidget.apply(this,arguments)},_getModalDialog:function(){return this.grid._rootContainer().find("#"+this.grid.id()+"_groupby_modalDialog")},changeGlobalLanguage:function(){},changeGlobalRegional:function(){},changeLocale:function(){var $dialog=this._getModalDialog(),self=this,colHeaderText;this._setGroupAreaTextContent($(".ui-iggrid-groupbyarea .ui-iggrid-groupbyareatext",this.grid.container()));this._super($(".ui-iggrid-grouparealist",this.grid.container()));this._super($("tbody>tr.ui-iggrid-groupedrow",this.grid.container()));this.grid.container().find("tr.ui-iggrid-summaryrow>td[gbsummaryiconcell]").each(function(){$(this).attr("title",self._getSummaryIconTitle($(this).data("colheader"),$(this).data("groupval")))});if($dialog.length){$dialog[this.options.dialogWidget]("option","locale",{modalDialogCaptionText:this._getLocaleValue("modalDialogCaptionText"),buttonApplyText:this._getLocaleValue("modalDialogButtonApplyText"),buttonCancelText:this._getLocaleValue("modalDialogButtonCancelText")});this._super($dialog);$dialog.find("a[data-localeid='modalDialogGroupByButtonText']").each(function(){colHeaderText=$(this).parent().next("span.ui-iggrid-dialog-text").text();$(this).attr("aria-label",self._getLocaleValue("modalDialogGroupByButtonText")+" "+colHeaderText)});$dialog.find("button[data-localeid='modalDialogCaptionButtonUngroup']").each(function(){colHeaderText=$(this).prev("span.ui-iggrid-dialog-text").text();$(this).attr("aria-label",self._getLocaleValue("modalDialogCaptionButtonUngroup")+" "+colHeaderText)})}},_registerWidget:$.noop,_unregisterWidget:$.noop,changeRegional:function(){var html;if(this.options.groupedColumns.length>0){html=this._generateGroupByRowsMarkup(this._getDataView(),this._startRowIndex,this._endRowIndex);this.grid.element.find(">tbody").empty().html(html)}},_setOption:function(key,value){var modalDialog=this._getModalDialog();this._super(key,value);if(key==="expansionIndicatorVisibility"){throw new Error(this._getLocaleValue("optionChangeNotSupported").replace("{optionName}",key))}switch(key){case"modalDialogGroupByOnClick":this._getModalDialog().remove();this._renderGroupByDialog();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;case"groupByAreaVisibility":this._setGroupByAreaVisibility(value);break;default:break}},_setGroupByAreaVisibility:function(groupByAreaVisibility){var groupby=this,$footer,caption,groupbyarea=$("#"+this.grid.element.attr("id")+"_groupbyarea"),init=this.grid._initialized,$cntnr=this.grid.container();groupbyarea.remove();if(groupByAreaVisibility==="top"){caption=this.grid._caption();groupbyarea=caption.length?$("<div></div>").insertAfter(caption):$("<div></div>").prependTo($cntnr)}else if(groupByAreaVisibility==="bottom"){$footer=$cntnr.find(".ui-iggrid-footer").last();if(init&&$footer.length&&$footer.is(":visible")){groupbyarea=$("<div></div>").insertBefore($footer)}else{groupbyarea=$("<div></div>").appendTo($cntnr)}}else if(groupByAreaVisibility==="hidden"){if(init){this.grid._initializeHeights()}return}groupbyarea.attr("id",this.grid.element.attr("id")+"_groupbyarea").addClass(this.css.groupByArea);this._setGroupAreaTextContent($("<span></span>").appendTo(groupbyarea).addClass(this.css.groupByAreaText));groupbyarea.droppable({accept:"th:not([ groupby-disabled ])",hoverClass:groupby.css.groupByAreaDropHover,drop:function(event,ui){var accepted,isdescendant;isdescendant=ui.draggable.closest(".ui-iggrid-root").attr("id")===groupby.grid.id()||ui.draggable.closest(".ui-iggrid").find(".ui-iggrid-root").length>0;if(!groupby.grid.element.hasClass("ui-iggrid-root")){isdescendant=true}accepted=ui.draggable.hasClass("ui-iggrid-header")&&isdescendant;if(accepted){groupby._groupBy(event,ui.draggable)}}});if(this.grid._isMultiColumnGrid){groupbyarea.droppable("option","tolerance","touch")}if(init){this.grid._initializeHeights();this._groupAreaList()}},_headerRendered:function(event,args){if(args.owner.id()!==this.grid.id()){return}if(args.owner.element.attr("data-childgrid")){return}this._renderGroupByDialog();this._setGroupByAreaVisibility(this.options.groupByAreaVisibility)},_renderGroupByDialog:function(){var $buttonOK,containment,self=this,o=this.options,$captionButtonContainer,modalDialog;if(this.options.groupByDialogContainment==="owner"){containment=this.grid.container()}else{containment="window"}modalDialog=$("<div></div>").appendTo(this.grid._rootContainer()).attr("id",this.grid.id()+"_groupby_modalDialog");modalDialog[this.options.dialogWidget]({renderFooterButtons:!o.modalDialogGroupByOnClick,modalDialogWidth:o.modalDialogWidth,modalDialogHeight:o.modalDialogHeight,animationDuration:o.modalDialogAnimationDuration,locale:{modalDialogCaptionText:self._getLocaleValue("modalDialogCaptionText"),buttonApplyText:self._getLocaleValue("modalDialogButtonApplyText"),buttonCancelText:self._getLocaleValue("modalDialogButtonCancelText")},containment:containment,gridContainer:this.grid.container(),modalDialogOpening:function(event,args){return self._groupByDialogOpening(event,args)},modalDialogOpened:function(){self._trigger(self.events.modalDialogOpened,null,{modalDialogElement:modalDialog,owner:self})},modalDialogMoving:function(e,ui){self._trigger(self.events.modalDialogMoving,null,{modalDialogElement:e.target,owner:self,originalPosition:ui.originalPosition,position:ui.position})},modalDialogClosing:function(){return self._trigger(self.events.modalDialogClosing,null,{modalDialogElement:modalDialog,owner:self})},modalDialogClosed:function(){self._trigger(self.events.modalDialogClosed,null,{modalDialogElement:modalDialog,owner:self})}});if(o.modalDialogGroupByOnClick){$captionButtonContainer=modalDialog[this.options.dialogWidget]("getCaptionButtonContainer");$("<span></span>").addClass("ui-icon ui-icon-closethick").appendTo($("<a></a>").appendTo($captionButtonContainer).attr({title:this._getLocaleValue("columnChooserCloseButtonTooltip"),href:"#",role:"button","data-localeid":"columnChooserCloseButtonTooltip","data-localeattr":"title"}).bind("click.hiding",function(event){modalDialog[o.dialogWidget]("closeModalDialog",true,event);event.preventDefault();event.stopPropagation();return false}).addClass("ui-dialog-titlebar-close ui-corner-all"))}else{$captionButtonContainer=modalDialog[this.options.dialogWidget]("getCaptionButtonContainer");$buttonOK=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_footer_buttonok");$buttonOK.bind("igbuttonclick",function(e){self._groupByDialogButtonOKClick(e)})}},openGroupByDialog:function(){var modalDialog=this._getModalDialog();modalDialog[this.options.dialogWidget]("openModalDialog")},closeGroupByDialog:function(){var modalDialog=this._getModalDialog();modalDialog[this.options.dialogWidget]("closeModalDialog")},_groupByDialogOpening:function(){var noCancel,modalDialog=this._getModalDialog();noCancel=this._trigger(this.events.modalDialogOpening,null,{modalDialogElement:modalDialog,owner:this});if(noCancel){this.renderGroupByModalDialog()}return noCancel},renderGroupByModalDialog:function(){var $content,i,self=this,o=this.options,css=this.css,modalDialog=this._getModalDialog(),noCancel,$groupedColumns,$ungroupedColumns;noCancel=this._trigger(this.events.modalDialogContentsRendering,null,{modalDialogElement:modalDialog,owner:this});if(noCancel){$content=modalDialog[this.options.dialogWidget]("getContent");$content.empty();self._tempGroupedColumns=o.groupedColumns.slice(0);self._tempOrderedGroupedCols=self._orderedGroupedCols.slice(0);self._tempSortingExpr=self.grid.dataSource.settings.sorting.expressions.slice(0);self._tempOptions={columnLayouts:[]};if(this.grid.options.columnLayouts&&this.grid.options.columnLayouts.length>0){for(i=0;i<this.grid.options.columnLayouts.length;i++){self._tempOptions.columnLayouts.push($.extend(true,{},this.grid.options.columnLayouts[i]))}this._renderLayoutsDropDown()}$groupedColumns=$("<div></div>").attr("id",this.grid.id()+"_groupby_modalDialog_groupedcolumns").addClass(css.dialogGroupedColumns).appendTo($content);$ungroupedColumns=$("<div></div>").attr("id",this.grid.id()+"_groupby_modalDialog_ungroupedcolumns").addClass(css.dialogUnroupedColumns).appendTo($content);$("<ul></ul>").addClass(css.dialogListGroupedColumns).appendTo($groupedColumns);$("<ul></ul>").addClass(css.dialogListUngroupedColumns).appendTo($ungroupedColumns);this._renderColumnsDialog(this.grid.options.columns);this._currentTreeLayer=null;if(this._isToRenderClearAllButton()){this._renderDialogButtonClearAll()}else{this.grid.container().find("#"+this.grid.id()+"_groupbydialog_reset_button").remove()}this._trigger(this.events.modalDialogContentsRendered,null,{modalDialogElement:modalDialog,owner:this})}},_renderLayoutsDropDown:function(){var o=this.options,fn,w,dW,$ddField,self=this,css=this.css,modalDialog=this._getModalDialog(),$content=modalDialog[this.options.dialogWidget]("getContent"),cancelFunc,htmlLayouts,$buttonDD,$dropDown,$tree,dropDownId=this.grid.id()+"_groupby_modalDialog_layoutsDD",modalDialogDropDownAreaWidth=o.modalDialogDropDownAreaWidth||o.modalDialogDropDownWidth,columnLayoutsData=this.grid.options.columnLayouts.slice(0),$layoutsContainer;$layoutsContainer=$("<div></div>").attr("id",this.grid.id()+"_groupby_modalDialog_layoutsContainer").addClass(css.modalDialogLayoutsContainer).appendTo($content);htmlLayouts="<div style='float: left;'>"+this._getLocaleValue("modalDialogDropDownLabel")+"</div>"+"<div class='"+css.dialogLayoutsDD+"'>"+"\t<div id='"+this.grid.id()+"_groupby_modalDialog_layoutsDDField' class='"+css.dialogLayoutsDDField+"'>"+this._getLocaleValue("modalDialogRootLevelHierarchicalGrid")+"</div>"+"\t<span id='"+this.grid.id()+"_groupby_modalDialog_layoutsDDButton' style='float:right;'>^</span>"+"\t<div style='clear: both;'></div>"+"</div>"+"<div style='clear: both;'></div>";$layoutsContainer.html(htmlLayouts);$buttonDD=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_layoutsDDButton");$buttonDD.wrap("<a href='#' title='"+this._getLocaleValue("modalDialogDropDownButtonCaption")+" '></a>");cancelFunc=function(e){e.preventDefault();e.stopPropagation()};$buttonDD.closest("div").bind({mousedown:function(event){self._toggleDropDown(event,false)},mouseup:cancelFunc,click:cancelFunc});$buttonDD.addClass(css.dialogLayoutsDDButton);if(this._checkIsGroupByInherit(this.grid.options)===false){columnLayoutsData=this._getEnabledGroupByLayouts(columnLayoutsData)}if(columnLayoutsData.length>0||this._checkIsGroupByEnabled(this.grid.options)){$dropDown=this.grid.container().find("#"+dropDownId);$dropDown.remove();$dropDown=$("<div></div>");$dropDown.attr("id",dropDownId).css({position:"absolute",display:"none","z-index":"1000"}).addClass(this.css.dropDownLayoutsContainer).appendTo(this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_content")).bind({mousedown:function(){clearTimeout(self._dropDownTimeout);setTimeout(function(){$buttonDD.closest("a").focus()},10)}});if(o.modalDialogDropDownWidth){$buttonDD.closest("div").width(o.modalDialogDropDownWidth)}if(modalDialogDropDownAreaWidth){$dropDown.width(modalDialogDropDownAreaWidth)}if(o.modalDialogDropDownWidth&&(!o.modalDialogDropDownWidth.indexOf||o.modalDialogDropDownWidth.indexOf("%")===-1)){w=$buttonDD.closest("div").width()-$buttonDD.outerWidth();$ddField=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_layoutsDDField");$ddField.width(w);dW=$ddField.outerWidth()-w;if(dW>0){w-=dW;$ddField.width(w-2)}}$tree=$("<div></div>").attr("id",this.grid.id()+"_groupby_modal_treeLayouts").addClass(css.modalDialogTreeContainer);$tree.appendTo($dropDown);columnLayoutsData=[{key:"Root",columnLayouts:columnLayoutsData,isRoot:true}];$tree.igTree({dataSourceType:"json",pathSeparator:"/",dataSource:columnLayoutsData,initialExpandDepth:1e6,bindings:{textKey:"key",childDataProperty:"columnLayouts"},nodeClick:function(event,args){var data=args.node.data,keyLayout=data.key,$groupedUL=self.grid.container().find("#"+self.grid.id()+"_groupby_modalDialog_groupedcolumns ul"),$ungroupedUL=self.grid.container().find("#"+self.grid.id()+"_groupby_modalDialog_ungroupedcolumns ul");if(data.dislabledGroupBy===true){return}$groupedUL.empty();$ungroupedUL.empty();self.grid.container().find("#"+self.grid.id()+"_groupby_modalDialog_layoutsDDField").text(keyLayout);if(args.node.path.length===1){self._renderColumnsDialog(self.grid.options.columns);self._currentTreeLayer=null}else{self._currentTreeLayer=keyLayout;self._renderColumnsDialog(data.columns,keyLayout)}self._toggleDropDown()}});fn=function(){self._dropDownTimeout=setTimeout(function(){self.closeDropDown()},200)};$buttonDD.closest("a").bind({focus:function(){self._igTreeHasFocus=true;clearTimeout(self._dropDownTimeout)},blur:function(){self._igTreeHasFocus=false;fn()}});$tree.find("a").bind({focus:function(){clearTimeout(self._dropDownTimeout)},blur:function(){fn()}});$tree.find("span.ui-igtree-expander.ui-icon").bind({click:function(){clearTimeout(self._dropDownTimeout);setTimeout(function(){$buttonDD.closest("a").focus()},10)}})}},openDropDown:function(){var $dropDown=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_layoutsDD");if($dropDown.is(":visible")===false){this._toggleDropDown()}},closeDropDown:function(){var $dropDown=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_layoutsDD");if($dropDown.is(":visible")===true){this._toggleDropDown()}},_getEnabledGroupByLayouts:function(layouts){var resultLayouts=[],i,tempChildLayouts,layout;if(layouts){for(i=0;i<layouts.length;i++){tempChildLayouts=null;layout=$.extend(true,{},layouts[i]);if(layout.columnLayouts&&this._checkIsGroupByInherit(layout)===false){tempChildLayouts=this._getEnabledGroupByLayouts(layout.columnLayouts);if(tempChildLayouts&&tempChildLayouts.length>0){layout.columnLayouts=tempChildLayouts}else{layout.columnLayouts=null}}if(this._checkIsGroupByEnabled(layout)){resultLayouts.push(layout)}else if(layout.columnLayouts!==null&&layout.columnLayouts!==undefined){layout.dislabledGroupBy=true;resultLayouts.push(layout)}}}return resultLayouts},_checkIsGroupByInherit:function(layout){var i;if(layout&&layout.features){for(i=0;i<layout.features.length;i++){if(layout.features[i].name==="GroupBy"&&layout.features[i].inherit===true){return true}}}return false},_checkIsGroupByEnabled:function(layout){var i;if(layout&&layout.features){for(i=0;i<layout.features.length;i++){if(layout.features[i].name==="GroupBy"){return true}}}return false},_toggleDropDown:function(){var $button=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_layoutsDDButton").parent(),$modalDialogContent=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_content"),$layoutsDDField=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_layoutsDDField").parent(),left=0,top=0,$dropDown=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_layoutsDD"),isVisible=$dropDown.is(":visible")===true,self=this;if($dropDown.data("isAnimating")===true){return}if(!isVisible){top=$layoutsDDField.igOffset().top-$modalDialogContent.igOffset().top+$layoutsDDField.height()+1;left=$layoutsDDField.igOffset().left-$modalDialogContent.igOffset().left;$dropDown.css({top:top,left:left})}$dropDown.data("isAnimating",true);$dropDown.slideToggle(400,function(){var $layoutsDD=self.grid.container().find("#"+self.grid.id()+"_groupby_modalDialog_layoutsDD"),$tree=self.grid.container().find("#"+self.grid.id()+"_groupby_modal_treeLayouts");if($dropDown.is(":visible")===true){$button.focus();self._activeDropdown=$dropDown;if(!self.options.modalDialogDropDownAreaWidth&&!self.options.modalDialogDropDownWidth){if($layoutsDD.width()!==$tree.width()){$layoutsDD.width($tree.width())}}}else{self._activeDropdown=null}$dropDown.data("isAnimating",false)})},_groupByDialogButtonOKClick:function(e){var noCancel,noCancelGroupBy,i,j,len,tempGroupedCol,copy,o=this.options,$hTable,modalDialog=this._getModalDialog(),isToCallGroupedColumnsChanged=false;this._tempGroupedColumns=this._tempGroupedColumns||[];noCancel=this._trigger(this.events.modalDialogButtonApplyClick,null,{modalDialogElement:modalDialog,owner:this,groupedColumns:this._tempGroupedColumns,groupedColumnLayouts:this._tempOptions.columnLayouts,sortingExpr:this._tempSortingExpr});if(noCancel){noCancelGroupBy=this._trigger(this.events.groupedColumnsChanging,e,{owner:this,groupedColumns:o.groupedColumns,newGroupedColumns:{columns:this._tempGroupedColumns,layouts:this._tempOptions.columnLayouts},triggeredBy:"modalDialog"});if(noCancelGroupBy){if(this._orderedGroupedCols.length!==this._tempOrderedGroupedCols.length){isToCallGroupedColumnsChanged=true}else{len=this._orderedGroupedCols.length;for(i=0;i<len;i++){tempGroupedCol=this._tempOrderedGroupedCols[i];for(j=0;j<len;j++){if(tempGroupedCol.key===this._orderedGroupedCols[j].key&&tempGroupedCol.layout===this._orderedGroupedCols[j].layout){break}}if(j===len){isToCallGroupedColumnsChanged=true;break}}}this._orderedGroupedCols=this._tempOrderedGroupedCols;if(o.groupedColumns){o.groupedColumns=this._tempGroupedColumns}if(this.grid.options.columnLayouts){this.grid.options.columnLayouts=this._tempOptions.columnLayouts}if(this.grid.dataSource.settings.sorting.expressions){this.grid.dataSource.settings.sorting.expressions=!this.grid._isHierarchicalGrid||this.options.type==="remote"&&!this.grid.options.odata?this._tempSortingExpr:this._filterExpressionsByLayout(this._tempSortingExpr)}this._setExprFormatter(this.grid.dataSource.settings.sorting.expressions);if(this._isToRenderClearAllButton()===false){if($(".ui-iggrid-groupbyarea",this.grid.container()).find("ul li").length===0){this._isgroup=null}else{this._isgroup=false}}else{this._isgroup=true}$hTable=this.grid.headersTable();if(o.groupedColumns.length===0&&$hTable.find("thead tr").children().first().hasClass("ui-iggrid-expandheadercellgb")){if($.ig.util.isIE){this.grid.element.children("tbody").hide();$hTable.hide()}this.grid.element.find("colgroup").children().first().remove();if(this.grid.options.fixedHeaders){$hTable.find("colgroup").children().first().remove()}if(this.grid.options.fixedFooters&&this.grid.options.height!==null){this.grid.footersTable().find("colgroup").children().first().remove()}$hTable.find("thead tr").children("[ data-skip ]").first().remove()}copy=this._orderedGroupedCols.slice(0);this._orderedGroupedCols=[];this._ensureLabelsOrder(copy,this._orderedGroupedCols,this.grid.options);this._rebind();this._clearSortingSettings(this._tempGroupedColumns);if($.ig.util.isIE&&!$hTable.is(":visible")){$hTable.show()}if(this.grid.options.width!==null&&this.grid.options.width!==undefined){this.grid._updateGridContentWidth()}this.grid._trigger("headerExtraCellsModified",null,{owner:this});if(isToCallGroupedColumnsChanged===true){this.grid._onGroupedColumnsChanged(this._tempGroupedColumns);this._trigger(this.events.groupedColumnsChanged,e,{owner:this,groupedColumns:this._tempGroupedColumns,triggeredBy:"modalDialog"})}}e.preventDefault();e.stopPropagation();modalDialog[this.options.dialogWidget]("closeModalDialog",null,e)}},_clearSortingSettings:function(keys){if(!keys||!keys.length){return}var i,key,sorting=this.grid.element.data("igGridSorting");if(sorting){for(i=0;i<keys.length;i++){key=$.type(keys[i])!=="object"?keys[i]:keys[i].key;sorting._clearSortStateByColKey(key,true)}sorting._clearActiveHeader();sorting._curColKey=null;sorting._currentActiveHeader=null;sorting._saveSortingExpressions()}},_setSortingTempExpr:function(key,dir,layout){var i,layouts,found=-1,j,gc=this._tempGroupedColumns,gcTemp,sexpr,s=this._tempSortingExpr,settings,lobj;sexpr={fieldName:key,dir:dir,layout:layout,isGroupBy:true};for(j=0;j<s.length;j++){if(s[j].fieldName===key&&(s[j].layout===layout||!layout&&!s[j].layout)){found=j;break}}if(dir===""){if(found>-1){s.splice(found,1)}return}else{if(found>-1){if(s[found].isGroupBy){s[found]=sexpr}else{s.splice(found,1);this._addSortingExpression(s,sexpr)}}else{this._addSortingExpression(s,sexpr)}}if(gc.length===0&&!layout){gcTemp=this._tempGroupedColumns.slice(0);this._allGroupedCols(gcTemp);gc=gcTemp.slice(0)}for(i=0;i<this._tempOrderedGroupedCols.length;i++){if(this._tempOrderedGroupedCols[i].key===key&&(this._tempOrderedGroupedCols.layout&&this._tempOrderedGroupedCols.layout===layout||!this._tempOrderedGroupedCols.layout&&!layout)){this._tempOrderedGroupedCols[i].dir=dir;break}}if(layout){layouts=[];this._findLayout(layout,this._tempOptions,layouts);lobj=layouts[0];for(i=0;lobj.features&&i<lobj.features.length;i++){if(lobj.features[i].name==="GroupBy"){settings=lobj.features[i].columnSettings;for(j=0;j<settings.length;j++){if(settings[j].columnKey===key){settings[j].dir=dir;break}}break}}}},_setGroupByTempExpr:function(key,isGroupBy,dir,layout){var i,gexpr,expr,lobj,c,fcs,setting,layouts;if(layout){layouts=[];this._findLayout(layout,this._tempOptions,layouts);lobj=layouts[0];c=this._getColumnByLayoutKey(key,lobj.columns)}else{lobj=this.grid.options;c=this.grid.columnByKey(key)}if(layout){if(!lobj.features){lobj.features=[];lobj.features.push({name:"GroupBy",columnSettings:[]});fcs=lobj.features[0].columnSettings}else{for(i=0;i<lobj.features.length;i++){if(lobj.features[i].name==="GroupBy"){fcs=lobj.features[i].columnSettings;if(!fcs){lobj.features[i].columnSettings=[];fcs=lobj.features[i].columnSettings}break}}}for(i=0;i<fcs.length;i++){if(fcs[i].columnKey===key){if(!isGroupBy){fcs.splice(i,1)}else{setting=fcs[i]}break}}if(isGroupBy){if(!setting){fcs.push({columnKey:key,isGroupBy:isGroupBy,dir:dir})}else{setting.isGroupBy=isGroupBy;setting.dir=dir}}}gexpr={key:key,dir:dir,layout:layout,col:c,isGroupBy:isGroupBy};if(!layout){expr=this._tempGroupedColumns;for(i=0;i<expr.length;i++){if(expr[i].key===key){expr.splice(i,1);break}}if(isGroupBy){expr=expr.concat(gexpr)}this._tempGroupedColumns=expr}if(isGroupBy){this._tempOrderedGroupedCols.push(gexpr)}else{for(i=0;i<this._tempOrderedGroupedCols.length;i++){if(this._tempOrderedGroupedCols[i].key===key&&(this._tempOrderedGroupedCols.layout&&this._tempOrderedGroupedCols.layout===layout||!this._tempOrderedGroupedCols.layout)){$.ig.removeFromArray(this._tempOrderedGroupedCols,i);break}}}this._setSortingTempExpr(key,dir,layout)},_checkColumnIsGroupedInternal:function(key,layout,groupedColumns,options){var isGrouped=false,i,j,layouts,lobj,fcs;if(!layout){for(i=0;i<groupedColumns.length;i++){if(groupedColumns[i].key===key){isGrouped=true;break}}}else{layouts=[];this._findLayout(layout,options,layouts);lobj=layouts[0];if(lobj&&lobj.features){for(i=0;i<lobj.features.length;i++){if(lobj.features[i].name==="GroupBy"){fcs=lobj.features[i].columnSettings;if(fcs){for(j=0;j<fcs.length;j++){if(fcs[j].columnKey===key){if(fcs[j].isGroupBy){isGrouped=true}break}}}break}}}}return isGrouped},checkColumnIsGrouped:function(key,layout){return this._checkColumnIsGroupedInternal(key,layout,this.options.groupedColumns,this.grid.options)},_getAllColumns:function(columns,columnsRes){var i,columnsLength=columns.length;for(i=0;i<columnsLength;i++){if(columns[i].group){this._getAllColumns(columns[i].group,columnsRes)}else{columnsRes.push(columns[i])}}},_renderColumnsDialog:function(columns,layout){var self=this,columnsRes=[],groupedCols;if(this.grid._isMultiColumnGrid){this._getAllColumns(columns,columnsRes)}else{columnsRes=columns}groupedCols=(self._tempOrderedGroupedCols||[]).filter(function(col){if(col.layout===layout||!col.layout&&!layout){self._renderDialogGroupedColumn(col.col,layout);return true}});columnsRes.forEach(function(col){var cs,colKey=col.key,i,gcLength=groupedCols.length;for(i=0;i<gcLength;i++){if(groupedCols[i].key===colKey){return true}}if(self.options.type==="remote"&&(col.unboundDS===true||col.unbound===true)){return true}cs=self._getColumnSettingByKey(col.key);if(!cs||cs.allowGrouping){self._renderDialogUngroupedColumn(col,layout)}})},_clearAllGroupedColumns:function(){this._tempGroupedColumns=[];this._clearAllGroupedColumnsLayout(this._tempOptions)},_clearAllGroupedColumnsLayout:function(layout){var i,fcs;if(layout!==null&&layout.features){for(i=0;i<layout.features.length;i++){if(layout.features[i].name==="GroupBy"){fcs=layout.features[i].columnSettings;if(fcs){layout.features[i].columnSettings=[]}}}}for(i=0;layout.columnLayouts&&i<layout.columnLayouts.length;i++){this._clearAllGroupedColumnsLayout(layout.columnLayouts[i])}},_isToRenderClearAllButton:function(){if(this.options.modalDialogGroupByOnClick||this._tempGroupedColumns.length>0||this._checkRenderLayoutsClearAll(this.grid.options)){return true}return false},_checkRenderLayoutsClearAll:function(layout){var i,j,fcs;if(layout!==null&&layout.features){for(i=0;i<layout.features.length;i++){if(layout.features[i].name==="GroupBy"){fcs=layout.features[i].columnSettings;if(fcs){for(j=0;j<fcs.length;j++){if(fcs[j].isGroupBy){return true;
}}}}}}for(i=0;layout.columnLayouts&&i<layout.columnLayouts.length;i++){if(this._checkRenderLayoutsClearAll(layout.columnLayouts[i])===true){return true}}return false},_renderDialogGroupedColumn:function(column,layout){var i,j,s,$li,liHTML,$buttonUngroup,o=this.options,self=this,css=this.css,key=column.key,$ul=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_groupedcolumns ul"),buttonAscDescId=this.grid.id()+"_"+key+"_groupbydialog_groupedcolumns_buttonascdesc",buttonUngroupId=this.grid.id()+"_"+key+"_groupbydialog_groupedcolumns_buttonungroup",dir="asc",gc=null;this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog").css("width");if(!layout){for(i=0;i<self._tempGroupedColumns.length;i++){if(self._tempGroupedColumns[i].key===key){gc=self._tempGroupedColumns[i];dir=gc.dir;break}}}else{s=self._tempSortingExpr;for(j=0;j<s.length;j++){if(s[j].fieldName===key&&(s[j].layout===layout||!layout&&!s[j].layout)){dir=s[j].dir;break}}}$li=$("<li tabIndex='0'></li>").attr("id",self.grid.id()+"_"+key+"_groupbydialog_grouped_li").addClass(css.dialogGroupedItem);$li.appendTo($ul);liHTML="<span id='"+buttonAscDescId+"' class='"+css.dialogButtonAsc+"' role='button' title='"+self._getLocaleValue("modalDialogCaptionButtonAsc")+"'"+" data-localeid='modalDialogCaptionButtonAsc' data-localeattr='title'>"+"\t<span class='"+css.dialogButtonAscIcon+"'></span>"+"</span>"+"<span class='"+css.dialogGroupedColumnTextContainer+"'>"+column.headerText+"</span>"+"<button type='button' id='"+buttonUngroupId+"' class='"+css.dialogButtonUngroup+"' role='button' title='"+self._getLocaleValue("modalDialogCaptionButtonUngroup")+"'"+" data-localeid='modalDialogCaptionButtonUngroup' data-localeattr='title' aria-label='"+self._getLocaleValue("modalDialogCaptionButtonUngroup")+" "+column.headerText+"' >"+"\t<span class='"+css.dialogButtonUngroupContainer+"'></span>"+"\t<span class='ui-button-text' data-localeid='modalDialogCaptionButtonUngroup'>"+self._getLocaleValue("modalDialogCaptionButtonUngroup")+"</span>"+"</button>";$li.html(liHTML);$buttonUngroup=this.grid.container().find("#"+buttonUngroupId);self._setDialogButtonAscDesc(dir==="asc",key);$li.bind({keydown:function(e){if(e.keyCode===$.ui.keyCode.ENTER||e.keyCode===$.ui.keyCode.SPACE){$li.click();e.preventDefault();e.stopPropagation()}},click:function(){self._dialogButtonAscDescClick(key,layout)}});$buttonUngroup.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,$nextLi;noCancel=self._trigger(self.events.modalDialogUngroupingColumn,e,{key:key,layout:layout,owner:self});if(noCancel){$li.remove();if(o.modalDialogGroupByOnClick===true){self.ungroupByColumn(key,layout)}else{self._setGroupByTempExpr(key,false,"",layout)}$nextLi=self._renderDialogUngroupedColumn(column,layout);$nextLi.find(":focusable").first().focus();if(self.grid.container().find("#"+self.grid.id()+"_groupby_modalDialog_groupedcolumns ul li").length===0&&self._isToRenderClearAllButton()===false){self.grid.container().find("#"+self.grid.id()+"_groupbydialog_reset_button").remove()}self._trigger(self.events.modalDialogUngroupColumn,e,{key:key,layout:layout,owner:self,groupedColumns:self._tempGroupedColumns})}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(key,layout){var o=this.options,noCancel,$buttonAscDesc=this.grid.container().find("#"+this.grid.id()+"_"+key+"_groupbydialog_groupedcolumns_buttonascdesc"),modalDialog=this._getModalDialog(),isAsc=$buttonAscDesc.data("isAsc"),dir=isAsc?"desc":"asc";noCancel=this._trigger(this.events.modalDialogSortGroupedColumn,null,{modalDialogElement:modalDialog,owner:this,key:key,isAsc:!isAsc,layout:layout});if(noCancel){if(o.modalDialogGroupByOnClick===true){this._setSortingTempExpr(key,dir,layout);this.grid.dataSource.settings.sorting.expressions=this._filterExpressionsByLayout(this._tempSortingExpr);this._setExprFormatter(this.grid.dataSource.settings.sorting.expressions);this._rebind()}else{this._setSortingTempExpr(key,dir,layout)}this._setDialogButtonAscDesc(!isAsc,key)}},_setDialogButtonAscDesc:function(isAsc,key){var css=this.css,$buttonAscDesc=this.grid.container().find("#"+this.grid.id()+"_"+key+"_groupbydialog_groupedcolumns_buttonascdesc"),$spanIcon=$buttonAscDesc.find("span:eq(0)"),caption,localeAttrId;if(isAsc===true){$buttonAscDesc.removeClass(css.dialogButtonDesc).addClass(css.dialogButtonAsc);$spanIcon.removeClass(css.dialogButtonDescIcon).addClass(css.dialogButtonAscIcon);caption=this._getLocaleValue("modalDialogCaptionButtonAsc");localeAttrId="modalDialogCaptionButtonAsc"}else{$buttonAscDesc.removeClass(css.dialogButtonAsc).addClass(css.dialogButtonDesc);$spanIcon.removeClass(css.dialogButtonAscIcon).addClass(css.dialogButtonDescIcon);caption=this._getLocaleValue("modalDialogCaptionButtonDesc");localeAttrId="modalDialogCaptionButtonDesc"}$buttonAscDesc.data("isAsc",isAsc).attr("title",caption).attr("data-localeid",localeAttrId)},_renderDialogButtonClearAll:function(){if(this.options.modalDialogGroupByOnClick===true){return}var self=this,resetButtonId=self.grid.id()+"_groupbydialog_reset_button",modalDialog=this._getModalDialog(),$captionButtonContainer,$resetButton;if(this.grid.container().find("#"+resetButtonId).length===0){$captionButtonContainer=modalDialog[this.options.dialogWidget]("getCaptionButtonContainer");$resetButton=$("<button type='button'></button>").attr("id",resetButtonId).attr("data-localeid","modalDialogClearAllButtonLabel").appendTo($captionButtonContainer);$resetButton.igButton({labelText:self._getLocaleValue("modalDialogClearAllButtonLabel"),click:function(e){var noCancel,$groupedUL,$ungroupedUL,layouts=[];noCancel=self._trigger(self.events.modalDialogButtonResetClick,e,{modalDialogElement:modalDialog,owner:self});if(noCancel){self._clearAllGroupedColumns();self._tempSortingExpr=self.grid.dataSource.settings.sorting.expressions.slice(0);$groupedUL=self.grid.container().find("#"+self.grid.id()+"_groupby_modalDialog_groupedcolumns ul");$ungroupedUL=self.grid.container().find("#"+self.grid.id()+"_groupby_modalDialog_ungroupedcolumns ul");$groupedUL.empty();$ungroupedUL.empty();self._tempSortingExpr=[];self._tempOrderedGroupedCols=[];if(!self._currentTreeLayer){self._renderColumnsDialog(self.grid.options.columns)}else{self._findLayout(self._currentTreeLayer,self._tempOptions,layouts);if(layouts.length>0){self._renderColumnsDialog(layouts[0].columns,self._currentTreeLayer)}}$(this).remove()}}})}},_renderDialogUngroupedColumn:function(column,layout){var self=this,$li,$a,key=column.key,o=this.options,css=this.css,$ul=this.grid.container().find("#"+this.grid.id()+"_groupby_modalDialog_ungroupedcolumns ul");$li=$("<li></li>").attr("id",self.grid.id()+"_"+key+"_groupbydialog_grouped_li").addClass(css.dialogUngroupedItem).append("<span class='"+css.dialogUngroupedColumnsGroupByButton+"'><a href='#'></a></span> <span class='"+css.dialogUngroupedColumnsText+"'>"+column.headerText+"</span>");$li.appendTo($ul);$a=$li.find("a:first");$a.addClass(css.modalDialogSortByColumn);$a.html(self._getLocaleValue("modalDialogGroupByButtonText"));$a.attr("data-localeid","modalDialogGroupByButtonText");$a.attr("aria-label",self._getLocaleValue("modalDialogGroupByButtonText")+" "+column.headerText);$li.bind({click:function(e){var noCancel,$nextLi;noCancel=self._trigger(self.events.modalDialogGroupingColumn,e,{key:key,layout:layout,owner:self});if(noCancel){$li.remove();if(o.modalDialogGroupByOnClick){self.groupByColumn(key,layout)}else{self._setGroupByTempExpr(key,true,o.defaultSortingDirection,layout)}self._renderDialogButtonClearAll();$nextLi=self._renderDialogGroupedColumn(column,layout);$nextLi.find(":focusable").first().focus();self._renderDialogButtonClearAll();self._trigger(self.events.modalDialogGroupColumn,e,{key:key,layout:layout,owner:self,groupedColumns:self._tempGroupedColumns})}e.preventDefault();e.stopPropagation()}});return $li},_setGroupAreaTextContent:function($area){var text=this._getLocaleValue("emptyGroupByAreaContent"),linkText=this._getLocaleValue("emptyGroupByAreaContentSelectColumns"),linkTextCaption=this._getLocaleValue("emptyGroupByAreaContentSelectColumnsCaption"),$a,self=this;text=text.replace("{0}","<a href='#' id='"+this.grid.id()+"_link_selectcolumns' title='"+linkTextCaption+"' data-localeid='emptyGroupByAreaContentSelectColumns' data-localeattr='title'>"+linkText+"</a>");$area.html(text);$a=this.grid.container().find("#"+this.grid.id()+"_link_selectcolumns");$a.bind({click:function(e){self.openGroupByDialog();e.preventDefault();e.stopPropagation()}})},_headerCellDragCancel:function(){return false},_headerCellRendered:function(event,args){var groupby=this,cs,hg,hgTemp,isMultiColumnHeaderGrid=this.grid._isMultiColumnGrid;if(args.owner.id()!==this.grid.id()){return}if(args.isMultiColumnHeader===true){return}hg=groupby.grid.element.hasClass("ui-iggrid-root")?groupby.grid.container():groupby.grid.element.closest(".ui-iggrid-root");if(hg.length===0){hg=groupby.grid.container()}else{hgTemp=hg.closest(".ui-widget");if(hgTemp.length>0){hg=hgTemp}}cs=this._getColumnSettingByKey(args.columnKey);if(!$.ig.util.isIE||$.ig.util.browserVersion>=9){args.th.find(".ui-iggrid-headertext").css("width","100%")}if(cs&&cs.allowGrouping||!cs){args.th.draggable({containment:hg,appendTo:hg,distance:5,revert:"invalid",scroll:false,cancel:"div.ui-iggrid-indicatorcontainer",helper:function(event){var th,helperDOM;if($(event.target).is("span")){groupby._spanDragging=true}else{groupby._spanDragging=false}th=$(event.target).closest("th");helperDOM=th.clone().css("overflow","hidden").width(th.width()).addClass("ui-widget ui-iggrid").wrap($("<div class='"+groupby.css.dragMarkup+"'/>").width(th.outerWidth()));if(isMultiColumnHeaderGrid){helperDOM.height(th.height())}return helperDOM.parent()},opacity:groupby.options.labelDragHelperOpacity,drag:function(event,ui){var groupbyarea;groupby._isDragging=true;groupbyarea=$(".ui-iggrid-groupbyarea",hg);if(!groupbyarea.hasClass("ui-iggrid-groupbyareahover")&&!groupby._movingEnabled){if(groupby._spanDragging){ui.helper.find("span").css("cursor","no-drop")}else{ui.helper.css("cursor","no-drop")}}else{if(groupby._spanDragging){ui.helper.find("span").css("cursor","move")}else{ui.helper.css("cursor","move")}}},stop:function(){groupby._isDragging=false}}).bind({mouseover:groupby._headerMouseOverHandler,mouseout:groupby._headerMouseOutHandler});if(args.owner.element.attr("data-childgrid")){args.th.attr("data-layout",args.owner.options.key).attr("data-grid-id",args.owner.element.attr("id"))}}},_getColumnSettingByKey:function(key){var i;for(i=0;i<this.options.columnSettings.length;i++){if(this.options.columnSettings[i].columnKey===key){return this.options.columnSettings[i]}}},_renderRecords:function(ui,args){if(args.owner.id()!==this.grid.id()){return}if(this.options.groupedColumns.length>0){this._renderRecordsInternal(args)}else{return true}return false},_recordsRendered:function(ui,args){var currentScrollTop=$(window).scrollTop();if(!args.tbody.is(":visible")){args.tbody.css("display","")}if(this._scrolltop!==0&&currentScrollTop!==0&&this._scrolltop!==currentScrollTop){$(window).scrollTop(this._scrolltop)}},_generateGroupByRowsMarkup:function(ds,start,end){var i,html="",dsRow,rowHtml,idx,pre,app,grid=this.grid,dataRecCount=0;for(i=start;i<=end;i++){dsRow=ds[i];if(!dsRow.__gbRecord&&!dsRow.__gbSummaryRecord){rowHtml=grid._renderRecord(dsRow,i,false,dataRecCount);dataRecCount++;idx=rowHtml.indexOf(">")+1;pre=rowHtml.substring(0,idx);app=rowHtml.substring(idx);html+=pre+'<td class="'+this.css.nonGroupRowEmptyCell+'" data-skip="true" tabindex="'+this.grid.options.tabIndex+'"></td>'+app}else if(!dsRow.__gbRecord){html+=this._renderSummaryRecord(dsRow,i)}else{html+=this._renderGroupRow(dsRow,i)}}return html},_renderRecordsInternal:function(args){var grid=this.grid,ds,noCancel=true,dataSkipWidth=0,scrollContainer,start,end,vrtWnd,tbody=grid.element.children("tbody"),html,$thDataSkip;noCancel=grid._trigger(grid.events.rowsRendering,null,args);if(noCancel){ds=this._getDataView();if(this._colspan===undefined||this._colspan===null){this._determineColspan()}if(!grid.headersTable().find("thead tr th").hasClass("ui-iggrid-expandheadercellgb")){$thDataSkip=$("<th></th>").prependTo(grid.headersTable().find("thead tr:nth-child(1)")).addClass(this.css.expandHeaderCellGroupBy).addClass(this.css.headerExtraCell).attr("data-skip",true);if(grid._isMultiColumnGrid){$thDataSkip.attr("rowspan",grid._maxLevel+1)}}tbody.show();if(this.grid.options.virtualization){vrtWnd=args.vrtWnd;start=vrtWnd.start;end=vrtWnd.end;if(start===undefined){start=0;end=ds.length-1}if(start!==undefined&&end===undefined){end=start;if(end>ds.length-1){end=ds.length-1}start=0}if(start<0||start>ds.length-1){start=0;grid._startRowIndex=0}if(!start){grid._virtualRowCount=grid._determineVirtualRowCount();if(grid._virtualRowCount>ds.length){grid._virtualRowCount=ds.length}end=grid._virtualRowCount}else if(start>=end){grid._virtualRowCount=grid._determineVirtualRowCount();end=start+grid._virtualRowCount}if(end>ds.length-1){end=ds.length-1}if(!start&&!end&&ds.length){grid._virtualRowCount=grid._determineVirtualRowCount();grid._totalRowCount=grid._getTotalRowCount();if(grid._virtualRowCount>grid._totalRowCount){grid._virtualRowCount=grid._totalRowCount}end=grid._virtualRowCount-1}}else{start=0;end=ds.length-1}this._startRowIndex=start;this._endRowIndex=end;html=this._generateGroupByRowsMarkup(ds,start,end);this._expandedRowCount=0;if(window.MSApp===undefined){tbody.html(html)}else{MSApp.execUnsafeLocalFunction(function(){tbody.html(html)})}if(grid.options.width===null){grid._setContainerWidth(grid.container())}else{grid._updateGridContentWidth()}if(grid._persistVirtualScrollTop&&grid._prevFirstVisibleTROffset){if(grid.options.virtualization!==true&&grid.options.rowVirtualization!==true){grid.scrollContainer()[0].scrollTop=grid._prevFirstVisibleTROffset}}scrollContainer=grid._virtualcontainer().length>0?grid._virtualcontainer():grid.scrollContainer();if(this.options.groupedColumns.length>0&&scrollContainer.length>0&&grid.element.width()>scrollContainer.width()&&(grid.options.virtualization===true||grid.options.rowVirtualization===true)){$(grid.element).find(">colgroup>col[ data-skip=true ]").each(function(){dataSkipWidth+=parseInt(this.style.width,10)});grid._setGridContentWidth(grid._calculateContainerWidth(false)+dataSkipWidth)}tbody.find("[data-id='"+this._focusCellId+"']").find(">td[gbexpandcell]").focus();this._focusCellId=null;grid._buildVirtualDomForContinuousVirtualization();this.grid._trigger(this.grid.events.rowsRendered,null,{owner:this.grid,tbody:tbody})}},_encodeSummaryParams:function(owner,params){var cs=this.options.columnSettings,i,j,key;for(i=0;i<cs.length;i++){if(cs[i].summaries&&cs[i].summaries.length>0){for(j=0;j<cs[i].summaries.length;j++){key="gs("+cs[i].columnKey+")";if(params.extraParams[key]){params.extraParams[key]=params.extraParams[key]+","+cs[i].summaries[j].summaryFunction}else{params.extraParams[key]=cs[i].summaries[j].summaryFunction}}}}},_getCountFromMetadata:function(contents,gcval,idval){var n,mdata=this.grid.dataSource.metadata(this.options.resultResponseKey),k,nVal,mul=1,t;if(mdata&&mdata[gcval]){k=mdata[gcval];for(n in k){if(k.hasOwnProperty(n)){t=this.grid.columnByKey(gcval).dataType;nVal=n;if($.type(n)==="string"){if(t==="bool"){nVal=n.toLowerCase()==="true"?true:false}else if(t==="number"){nVal=mul*n}}if(idval!==null&&idval!==undefined&&!idval.length&&idval===nVal*mul||nVal===idval){contents=contents.replace(new RegExp("__sum__","g"),k[n])}}}}return contents},_calcRealSummary:function(contents,gcval,idval,subdata,allGroupData){var n,k,i,cs,j,mdata=this.grid.dataSource.metadata(this.options.resultResponseKey),o,str=contents,val,found=false,mul=1,t,kVal;n=this.grid.dataSource.data();if(mdata){str=this._getCountFromMetadata(str,gcval,idval);cs=this.options.columnSettings;for(i=0;i<cs.length;i++){for(j=0;j<cs[i].summaries.length;j++){o=mdata[cs[i].columnKey+"_"+cs[i].summaries[j].summaryFunction];for(k in o){if(o.hasOwnProperty(k)){t=this.grid.columnByKey(gcval).dataType;if(t==="bool"&&$.type(k)==="string"){kVal=k.toLowerCase()==="true"?true:false}else if(t==="number"&&$.type(k)==="string"){kVal=mul*k}else{kVal=k}if(idval!==null&&!idval.length&&idval===kVal*mul||kVal===idval){val=o[k];val=$.ig.formatter(val,"number",this.options.summarySettings.summaryFormat);if(cs[i].summaries[j].customSummary===undefined||cs[i].summaries[j].customSummary===null){str=str.replace(cs[i].columnKey+cs[i].summaries[j].summaryFunction+"$$value$$",val)}}}}}}}if(!found||this.grid._getDataView().length<n.length){return this._summaries(str,subdata,gcval,allGroupData)}},getGroupedData:function(data,colKey,idval){var i,len,res,ds=this.grid.dataSource,gbData=ds.groupByData(),vgbData=ds.visibleGroupByData();res=ds._generateGroupByData(data,[{fieldName:colKey,isGroupBy:true}]);if(idval!==undefined){len=res.length;for(i=0;i<len;i++){if(res[i].val===idval){res=res[i].recs;break}}}this._gbData=gbData;this._vgbData=vgbData;return res},_settingFromKey:function(key){var cs,j;for(j=0;j<this.options.columnSettings.length;j++){if(this.options.columnSettings[j].columnKey===key){cs=this.options.columnSettings[j]}}return cs},_renderGroupRow:function(gbRec,rowInd){var expcell,textcell,col,tr,val=gbRec.val,classAttr=this.grid._addCellStyle(gbRec),collapsed=gbRec.collapsed,field=gbRec.fieldName,indent=gbRec.level,colCustomSetting=this._settingFromKey(field),customName=colCustomSetting.customGroupName,margin=indent>0?parseInt(this.options.indentation,10)*indent:0,cscol,htext,text,state,css,i,cs=this.options.columnSettings,shtml="",tmpl,title,j,hide=false;if(!collapsed){css=this.css.groupByExpandCellExpanded;title=this._getLocaleValue("collapseTooltip")}else{css=this.css.groupByExpandCellCollapsed;title=this._getLocaleValue("expandTooltip");if(indent>0&&!this.grid.options.virtualization){hide=true}}if(this.options.expansionIndicatorVisibility){expcell="<td class='"+this.css.groupByExpandColumn+classAttr.replace(/class=\"/,"").replace(/\"/,"")+"' gbexpandcell='1'"+" tabindex='"+this.grid.options.tabIndex+"'><span class='ui-iggrid-expandbuttoncontainer-group-by' style='margin-left:"+margin+"px;'><span class='"+css+"' title='"+title+"'"+"data-localeid='"+(collapsed?"expandTooltip":"collapseTooltip")+"'"+"data-localeattr='title'"+"></span></span></td>"}else{expcell="<td class='"+this.css.groupByExpandColumn+classAttr.replace(/class=\"/,"").replace(/\"/,"")+"' gbexpandcell='1'></td>"}tmpl=this.options.groupedRowTextTemplate;col=this.grid.columnByKey(field);if(colCustomSetting&&colCustomSetting.groupLabelFormatter){if(typeof colCustomSetting.groupLabelFormatter==="function"){val=colCustomSetting.groupLabelFormatter(val)}else{val=window[colCustomSetting.groupLabelFormatter](val)}}else if(this.options.useGridColumnFormatter===true){val=this.grid._renderCell(val,col,gbRec.recs&&gbRec.recs.length?gbRec.recs[0]:null," ")}tmpl=tmpl.replace(new RegExp("\\$\\{key\\}","g"),col.headerText);if(customName){text=tmpl.replace(new RegExp("\\$\\{val\\}","g"),customName).replace(new RegExp("\\$\\{count\\}","g"),"__sum__")}else{text=tmpl.replace(new RegExp("\\$\\{val\\}","g"),val).replace(new RegExp("\\$\\{count\\}","g"),"__sum__")}if(!collapsed){state="expanded"}else{state="collapsed"}for(i=0;i<cs.length;i++){if(cs[i].columnKey!==field){cscol=this.grid.columnByKey(cs[i].columnKey);htext=cscol?cscol.headerText:cs[i].columnKey}else{htext=col.headerText}for(j=0;j<cs[i].summaries.length;j++){shtml+=" "+htext+" "+(cs[i].summaries[j].text||cs[i].summaries[j].summaryFunction)+" "+cs[i].columnKey+cs[i].summaries[j].summaryFunction+"$$value$$";if(j!==cs[i].summaries.length-1){shtml+=this.options.summarySettings.multiSummaryDelimiter}}}text+=shtml;textcell="<td data-gbsummary='true' colspan='"+this._colspan+"' tabindex='"+this.grid.options.tabIndex+"'"+classAttr+">"+text+"</td>";tr="<tr class='"+this.grid.css.recordClass+" "+this.css.groupedRow+"' data-grouprow='true' data-state='"+state+"' data-glevel='"+indent+"'"+" aria-expanded='"+(!collapsed?"true":"false")+"'"+" aria-describedby='"+this.grid.id()+"_"+col.key+"'"+" title='"+this._getLocaleValue("summaryRowTitle")+"'"+" data-localeid='summaryRowTitle'"+" data-localeattr='title'"+" data-id='"+gbRec.id+"'"+" data-row-idx='"+rowInd+"'"+" tabindex='"+this.grid.options.tabIndex+"' >"+expcell+textcell+"</tr>";tr=this._calcRealSummary(tr,gbRec.fieldName,gbRec.val,gbRec.recs,gbRec.recs);tr=tr.replace(new RegExp("__sum__","g"),gbRec.recs.length);return tr},_getSummaryIconTitle:function(colHeader,groupVal){return this._getLocaleValue("summaryIconTitle").replace("{0}",colHeader).replace("{1}",groupVal)},_renderSummaryRecord:function(gbRec,rowInd){var grid=this.grid,cols=grid.options.columns,indent=gbRec.level-1,margin=indent>0?parseInt(this.options.indentation,10)*indent:0,tr="",groupVal=gbRec.groupValue,colIndex,summIndex,summLabel,summValue,colSetting,i,emptyCells,compareFunc,col,cscol,colKey,colHeader,summaryIconTitle;tr+="<tr class='"+this.grid.css.recordClass+" "+this.css.summaryRow+"'"+" role='row'"+" aria-describedby='"+this.grid.id()+"_"+gbRec.id.split(":")[indent*2]+"'"+" aria-label='summaryrow"+"'"+" data-summaryrow='true' "+" data-glevel='"+(gbRec.level-1)+"'"+" data-id='"+gbRec.id+"_"+gbRec.position+"Summary"+"'"+" data-row-idx='"+rowInd+"'"+" tabindex='"+grid.options.tabIndex+"'"+">";colKey=gbRec.id.split(":")[indent*2];cscol=this.grid.columnByKey(colKey);colHeader=cscol?cscol.headerText:colKey;if(cscol&&(cscol.dataType==="date"||cscol.dataType==="time")){groupVal=new Date(parseInt(groupVal,10))}groupVal=this.grid._renderCell(groupVal,cscol);summaryIconTitle=this._getSummaryIconTitle(colHeader,groupVal);tr+="<td class='"+this.css.groupBySummaryIconColumn+"'"+" gbsummaryiconcell='1"+"'"+" tabindex='"+this.grid.options.tabIndex+"'"+" title='"+summaryIconTitle+"'"+" data-skip='true'"+" data-colheader='"+colHeader+"'"+" data-groupval='"+groupVal+"'"+">"+"<span class='ui-iggrid-summaryiconcontainer-group-by'>"+"<span class='"+this.css.groupBySummaryIcon+"' style='margin-left:"+margin+"px;'>"+"</span>"+"</span>"+"</td>";emptyCells=this.grid.headersTable().find("colgroup").children("[ data-skip ]").length-1;for(i=0;i<emptyCells;i++){tr+="<td class='"+this.css.groupBySummaryEmptyCellColumn+"'"+" gbsummaryemptycell='1'"+" tabindex='"+this.grid.options.tabIndex+"'></td>"}compareFunc=function(target){return target.columnKey===col.key};for(colIndex=0;colIndex<cols.length;colIndex++){col=cols[colIndex];if(col.hidden){continue}tr+="<td class='"+this.css.groupBySummaryColumn+"'"+" role='gridcell'"+" aria-describedby='"+this.grid.id()+"_"+cols[colIndex].key+"'"+" gbsummarycell='1'"+" tabindex='"+grid.options.tabIndex+"'>";if(!gbRec.summaries[col.key]){tr+="</td>";continue}for(summIndex=0;summIndex<gbRec.summaries[col.key].length;summIndex++){colSetting=this.options.columnSettings.filter(compareFunc);summValue=gbRec.summaries[col.key][summIndex];summLabel=colSetting[0].groupSummaries[summIndex].label;if((col.dataType==="date"||col.dataType==="time")&&colSetting[0].groupSummaries[summIndex].applyFormat){summValue=new Date(parseInt(summValue,10))}if(colSetting[0].groupSummaries[summIndex].applyFormat&&!colSetting[0].groupSummaries[summIndex].format){summValue=this.grid._renderCell(summValue,col)}else if(colSetting[0].groupSummaries[summIndex].applyFormat&&colSetting[0].groupSummaries[summIndex].format){summValue=$.ig.formatter(summValue,col.dataType,colSetting[0].groupSummaries[summIndex].format)}tr+="<div style='margin: 0'>"+colSetting[0].groupSummaries[summIndex].summaryTemplate.replace("{label}",summLabel).replace("{value}",summValue)+"</div>"}tr+="</td>"}tr+="</tr>";return tr},_renderNewRow:function(rec){var tbody=this.grid.element.children("tbody"),dataRows=tbody.children("tr:not([ data-container='true' ],[ data-grouprow='true' ])"),index=dataRows.length,row;row=$(this.grid._renderRecord(rec,index));dataRows.last().find("td."+this.css.nonGroupRowEmptyCell).removeClass(this.css.groupByLastEmptyCell);if(this.groupByColumns().length>0){$("<td></td>").addClass(this.css.nonGroupRowEmptyCell).addClass(this.css.groupByLastEmptyCell).attr("tabindex",this.grid.options.tabIndex).attr("data-skip",true).prependTo(row)}if(this.grid.options.virtualization){this.grid._buildVirtualDomForContinuousVirtualization()}MSApp.execUnsafeLocalFunction(function(){tbody.append(row)})},_summaries:function(contents,data,gcval,allGroupData){var i,j,cs=this.options.columnSettings,s,ret=contents,arr,val,argsData,format;if(contents&&contents.indexOf&&contents.indexOf("$$value$$")===-1){return contents}for(i=0;i<cs.length;i++){s=cs[i].summaries;if(s.length>0){arr=this._arr(cs[i].columnKey,data);for(j=0;j<s.length;j++){if(s[j].summaryFunction==="custom"){argsData={dataRecords:data,array:arr,key:gcval,allGroupData:allGroupData}}else{argsData=arr}val=$.ig.calcSummaries(s[j].summaryFunction,argsData,s[j].customSummary);var dType=this.grid.columnByKey(gcval).dataType;if((dType==="date"||dType==="time")&&(s[j].summaryFunction==="min"||s[j].summaryFunction==="max")){format=dType==="date"?$.ig.regional.defaults.datePattern:$.ig.regional.defaults.timePattern;val=$.ig.formatter(new Date(val),"date",format)}else{val=$.ig.formatter(val,"number",this.options.summarySettings.summaryFormat)}ret=ret.replace(cs[i].columnKey+s[j].summaryFunction+"$$value$$",val)}}}return ret},_arr:function(key,data){var arr=[],i;for(i=0;i<data.length;i++){arr.push(data[i][key])}return arr},_dataEmpty:function(event,args){var indent=0,indentation=parseInt(this.options.indentation,10),$cntnr,gcols=this.options.groupedColumns;if(args.owner.id()!==this.grid.id()){return}if(gcols.length>0){indent+=indentation*this.options.groupedColumns.length;if(this.options.indentation&&this.options.indentation.indexOf&&this.options.indentation.indexOf("%")>=0){indent=this.options.indentation}this._indent=indent;this._addOrUpdateDataSkipCol(indent)}$cntnr=this.grid.container();if(this._isgroup!==null&&this._isgroup!==undefined&&$cntnr.length&&$cntnr[0].style.width&&!this.grid.options.width){if(this._isgroup===true){if(this.grid.options.virtualization!==true){$cntnr.width(parseInt($cntnr.width(),10)+indentation)}}else{$cntnr.width(parseInt($cntnr.width(),10)-indentation);indentation*=-1}if(this.grid.options.virtualization===true&&this.grid.options.virtualizationMode==="continuous"){this.grid._setDisplayContainerWidth(this.grid._getDisplayContainerWidth()+indentation);this.grid._setVHeadersWidth(this.grid._getVHeadersWidth()+indentation)}this._isgroup=null}this._tbody=args.tbody;if(!this._isgroup&&this.groupByColumns().length>0){this._groupAreaList()}event.stopPropagation()},_checkGroupExists:function(key){var exists=false,i;for(i=0;i<this.options.groupedColumns.length;i++){if(this.options.groupedColumns[i].key===key){exists=true;break}}return exists},_groupBy:function(event,th){var noCancel,key,layout,cgrid,eArgs,exists=false;layout=th.attr("data-layout");if(layout){cgrid=this.grid.container().find("#"+th.attr("data-grid-id")).data("igGrid");key=cgrid.options.columns[th.data("columnIndex")].key}else{if(th.data("columnIndex")===null||th.data("columnIndex")===undefined){return}key=this.grid.options.columns[th.data("columnIndex")].key;cgrid=this.grid}if(!layout){exists=this._checkGroupExists(key)}if(exists){return}eArgs={owner:this,groupedColumns:this.options.groupedColumns,key:key,layout:layout,grid:cgrid,triggeredBy:"dragAndDrop"};noCancel=this._trigger(this.events.groupedColumnsChanging,event,eArgs);if(noCancel){this.groupByColumn(key,layout);this._trigger(this.events.groupedColumnsChanged,event,eArgs)}},groupByColumns:function(){var gc=[];if(this._hierarchical){gc=this._orderedGroupedCols}else{gc=this.options.groupedColumns}return gc},_ensureLabelsOrder:function(from,to,layout){var i,key=layout?layout.key:null;for(i=0;i<from.length;i++){if((from[i].layout===key||!from[i].layout&&!key)&&!this._exists(to,from[i])){to.push(from[i])}}for(i=0;layout.columnLayouts&&i<layout.columnLayouts.length;i++){this._ensureLabelsOrder(from,to,layout.columnLayouts[i])}},_exists:function(arr,layout){var i;for(i=0;i<arr.length;i++){if((arr[i].layout===layout.layout||!arr[i].layout&&!layout.layout)&&arr[i].key===layout.key){return true}}return false},_findLayout:function(layout,opts,layouts){var i;if(opts.key===layout){layouts.push(opts)}else if(!layout){layouts.push(this.grid.options)}else{for(i=0;opts.columnLayouts&&i<opts.columnLayouts.length;i++){this._findLayout(layout,opts.columnLayouts[i],layouts)}}},_isGroupColumn:function(key,layout,gc){var i,gcLen=gc.length;for(i=0;i<gcLen;i++){if(gc[i].key===key&&gc[i].layout===layout){return true}}return false},_allGroupedCols:function(gc){var i,j,key,layout,isToAdd;for(i=0;i<this.options.groupedColumns.length;i++){key=this.options.groupedColumns[i].key;layout=this.options.groupedColumns[i].layout;isToAdd=true;for(j=0;j<gc.length;j++){if(key===gc[j].key&&layout===gc[j].layout){this.options.groupedColumns[i]=gc[j];isToAdd=false;break}}if(isToAdd){gc.push(this.options.groupedColumns[i])}}this._addGroupsRecursive(gc,this.grid.options.columnLayouts)},_addGroupsRecursive:function(gc,layouts){var i,j,gb,col,k,persist;if(!layouts){return}for(i=0;i<layouts.length;i++){for(j=0;layouts[i].features&&j<layouts[i].features.length;j++){if(layouts[i].features[j].name==="GroupBy"){gb=layouts[i].features[j];break}}if(gb){persist=gb.persist||this.options.persist;for(j=0;gb.columnSettings&&gb.columnSettings.length&&j<gb.columnSettings.length;j++){if(gb.columnSettings[j].isGroupBy){if(persist&&gb.columnSettings[j].columnKey){if(this._isGroupColumn(gb.columnSettings[j].columnKey,layouts[i].key,gc)){continue}}for(k=0;k<layouts[i].columns.length;k++){if(layouts[i].columns[k].key===gb.columnSettings[j].columnKey||gb.columnSettings[j].columnIndex===k){col=layouts[i].columns[k];break}}gc.push({key:gb.columnSettings[j].columnKey||col.key,layout:layouts[i].key,dir:gb.columnSettings[j].dir,col:col})}}}gb=null;this._addGroupsRecursive(gc,layouts[i].columnLayouts)}},_getColumnByLayoutKey:function(key,columns){var c,i;if(this.grid._isMultiColumnGrid){for(i=0;i<columns.length;i++){if(columns[i].key===key){c=columns[i];break}if(columns[i].group!==undefined&&columns[i].group!==null){c=this._getColumnByLayoutKey(key,columns[i].group);if(c!==undefined&&c!==null){break}}}}else{for(i=0;i<columns.length;i++){if(columns[i].key===key){c=columns[i];break}}}return c},groupByColumn:function(key,layout,sortingDirection){var i,expr,gexpr,lobj,c,fcs,setting,layouts,exists=this._checkGroupExists(key),copy,dir="asc";this.grid._onGroupedColumnsChanging(this.options.groupedColumns);if(sortingDirection!==undefined&&sortingDirection!==null){dir=sortingDirection}else if(this.options.defaultSortingDirection!==undefined){dir=this.options.defaultSortingDirection}if(!layout&&exists){return}if(layout){layouts=[];this._findLayout(layout,this.grid.options,layouts);lobj=layouts[0];c=this._getColumnByLayoutKey(key,lobj.columns)}else{lobj=this.grid.options;c=this.grid.columnByKey(key)}if(layout){if(!lobj.features){lobj.features=[];lobj.features.push({name:"GroupBy",columnSettings:[]});fcs=lobj.features[0].columnSettings}else{for(i=0;i<lobj.features.length;i++){if(lobj.features[i].name==="GroupBy"){fcs=lobj.features[i].columnSettings;if(!fcs){lobj.features[i].columnSettings=[];fcs=lobj.features[i].columnSettings}break}}}for(i=0;i<fcs.length;i++){if(fcs[i].columnKey===key){if(fcs[i].isGroupBy){return}setting=fcs[i];break}}if(!setting){fcs.push({columnKey:key,isGroupBy:true,dir:dir})}else{setting.isGroupBy=true}}expr={fieldName:key,dir:dir,layout:layout,isGroupBy:true};gexpr={key:key,dir:dir,layout:layout,
col:c};if(!layout){this.options.groupedColumns.push(gexpr)}this._orderedGroupedCols.push(gexpr);copy=this._orderedGroupedCols.slice(0);this._orderedGroupedCols=[];this._ensureLabelsOrder(copy,this._orderedGroupedCols,this.grid.options);this.grid._trigger("headerExtraCellsModified",null,{owner:this});if(!layout||this.options.type==="remote"&&!this.grid.options.odata){this._addSortingExpression(this.grid.dataSource.settings.sorting.expressions,expr)}if(!layout){this._clearSortingSettings([key]);this._isgroup=true}this._setExprFormatter(this.grid.dataSource.settings.sorting.expressions);this._rebind();this.grid._onGroupedColumnsChanged(this.options.groupedColumns)},_setExprFormatter:function(exprs){this.grid._getSortingExpressionsManager().setFormattersForSortingExprs(exprs,this.grid)},_addSortingExpression:function(se,expr){return this.grid._getSortingExpressionsManager().addSortingExpression(se,expr,this)},ungroupByColumn:function(key,layout){var i,j,self=this,fcs,lobj,layouts=[],exprs=this.grid.dataSource.settings.sorting.expressions,exists=this._checkGroupExists(key),copy;if(!layout&&!exists){return}this.grid._onGroupedColumnsChanging(this.options.groupedColumns);if(!layout){for(i=0;i<this.options.groupedColumns.length;i++){if(this.options.groupedColumns[i].key===key){$.ig.removeFromArray(this.options.groupedColumns,i);break}}}else{this._findLayout(layout,this.grid.options,layouts);lobj=layouts[0];if(lobj){lobj.features=lobj.features||[];for(i=0;i<lobj.features.length;i++){if(lobj.features[i].name==="GroupBy"){fcs=lobj.features[i].columnSettings||[];for(j=0;j<fcs.length;j++){if(fcs[j].columnKey===key){$.ig.removeFromArray(fcs,j);break}}break}}}}for(i=0;i<this._orderedGroupedCols.length;i++){if(this._orderedGroupedCols[i].key===key&&(this._orderedGroupedCols[i].layout&&this._orderedGroupedCols[i].layout===layout||!this._orderedGroupedCols[i].layout&&(layout===""||layout===undefined))){$.ig.removeFromArray(this._orderedGroupedCols,i);break}}for(i=0;i<exprs.length;i++){if(exprs[i].fieldName===key&&(!layout||layout&&layout===exprs[i].layout)){if(exprs[i].isSorting){exprs[i].isGroupBy=undefined}else{$.ig.removeFromArray(exprs,i)}}}copy=this._orderedGroupedCols.slice(0);this._orderedGroupedCols=[];this._ensureLabelsOrder(copy,this._orderedGroupedCols,this.grid.options);this.grid._trigger("headerExtraCellsModified",null,{owner:this});this.grid.element.children("tbody").hide();if(document.documentMode===8){this.grid.element.hide();this.grid.headersTable().hide()}if(!layout&&this.options.groupedColumns.length===0){this.grid.element.find("colgroup").children().first().remove();if(this.grid.options.fixedHeaders){this.grid.headersTable().find("colgroup").children().first().remove()}if(this.grid.options.fixedFooters&&this.grid.options.height!==null){this.grid.footersTable().find("colgroup").children().first().remove()}this.grid.headersTable().find("thead tr").children("[ data-skip ]").first().remove()}if(!layout){this._isgroup=false}this._rebind();if(document.documentMode===8){this.grid.headersTable().show();this.grid.element.show()}if(this.options.groupedColumns.length===0){if(window.mozInnerScreenX!==undefined&&self.grid.options.fixedFooters===true){self.grid.footersTable().hide();setTimeout(function(){self.grid.footersTable().show()},0)}this._setGroupAreaTextContent($(".ui-iggrid-groupbyarea .ui-iggrid-groupbyareatext",this.grid.container()));if(this.grid.options.width!==null&&this.grid.options.width!==undefined){this.grid._updateGridContentWidth()}}this.grid._onGroupedColumnsChanged(this.options.groupedColumns)},_clearSettings:function(layouts){var i,j,cs,k;for(i=0;i<layouts.length;i++){if(layouts[i].features&&layouts[i].features.length){for(j=0;j<layouts[i].features.length;j++){if(layouts[i].features[j].name==="GroupBy"){cs=layouts[i].features[j].columnSettings;if(cs){for(k=0;k<cs.length;k++){cs[k].isGroupBy=false}}}}}if(layouts[i].columnLayouts){this._clearSettings(layouts[i].columnLayouts)}}},expand:function(rowId){this._expandCollapseRow(rowId,true)},collapse:function(rowId){this._expandCollapseRow(rowId,false)},ungroupAll:function(){var indent=0,i,layouts=this.grid.options.columnLayouts,cols=this.groupByColumns(),hasRoot=false;if(cols.length===0){return}this.grid._onGroupedColumnsChanging(this.options.groupedColumns);for(i=1;i<this.options.groupedColumns.length;i++){indent+=parseInt(this.options.indentation,10)}if(parseInt(this.grid.container().width(),10)>0&&!this.grid.options.width){this.grid.container().width(parseInt(this.grid.container().width(),10)-indent)}this.grid.dataSource.settings.sorting.expressions=[];this.options.groupedColumns=[];this._orderedGroupedCols=[];if(!this._hierarchical){cols=[]}else{for(i=0;i<cols.length;i++){if(!cols[i].layout){hasRoot=true;break}}if(hasRoot){cols=[]}}if(layouts){this._clearSettings(layouts)}if(this.options.groupedColumns.length===0&&cols.length===0){this.grid.element.find("colgroup").children().first().remove();if(this.grid.options.fixedHeaders){this.grid.headersTable().find("colgroup").each(function(){$(this).children("[ data-skip ]").first().remove()})}if(this.grid.options.fixedFooters){this.grid.footersTable().find("colgroup").each(function(){$(this).children("[ data-skip ]").first().remove()})}this.grid.headersTable().find("thead tr").each(function(){$(this).children("[ data-skip ]").first().remove()});this.grid.footersTable().find("tfoot tr").each(function(){$(this).children("[ data-skip ]").first().remove()})}this._isgroup=false;this._rebind();if(this.options.groupedColumns.length===0){if(this.grid.options.width!==null&&this.grid.options.width!==undefined){this.grid._updateGridContentWidth()}}this.grid._onGroupedColumnsChanged([])},_regroup:function(){var items=$(".ui-iggrid-groupbyarea",this.grid.container()).find("ul li"),groupby=this,i,copy,gbObj,eArgs,noCancel,sExprs=[],gbExprs=[];this.options.groupedColumns=[];this.grid.dataSource.settings.sorting.expressions=[];copy=this._orderedGroupedCols.slice(0);this._orderedGroupedCols=[];items.each(function(){var direction,k,layout,c,lobj,layouts=[],sExpr;k=$(this).attr("data-key");layout=$(this).attr("data-layout");direction=$(this).find(".ui-iggrid-asc").length>0?"asc":"desc";if(layout){groupby._findLayout(layout,groupby.grid.options,layouts);lobj=layouts[0];for(i=0;lobj&&i<lobj.columns.length;i++){if(lobj.columns[i].key===k){c=lobj.columns[i];break}}}else{c=groupby.grid.columnByKey(k)}gbObj={key:k,dir:direction,col:c,layout:layout};sExpr={fieldName:k,dir:direction,isGroupBy:true};if(layout){sExpr.layout=layout}gbExprs.push(gbObj);sExprs.push(sExpr)});eArgs={owner:this,groupedColumns:gbExprs,triggeredBy:"regroup"};noCancel=this._trigger(this.events.groupedColumnsChanging,null,eArgs);if(noCancel){for(i=0;i<gbExprs.length;i++){groupby._addSortingExpression(groupby.grid.dataSource.settings.sorting.expressions,sExprs[i]);groupby._orderedGroupedCols.push(gbExprs[i]);if(!gbExprs[i].layout){groupby.options.groupedColumns.push(gbExprs[i])}}groupby._setExprFormatter(groupby.grid.dataSource.settings.sorting.expressions);groupby._ensureLabelsOrder(copy,groupby._orderedGroupedCols,groupby.grid.options);this.grid._loadingIndicator.show();this._saveSortingExpressions();this._rebindDataSource();this._trigger(this.events.groupedColumnsChanged,null,eArgs)}},_rebind:function(){this._scrolltop=$(window).scrollTop();this.grid._loadingIndicator.show();this._saveSortingExpressions();this._rebindDataSource();this._groupAreaList()},_rebindDataSource:function(){var ds=this.grid.dataSource,root,gb,cols,layout=this.grid.options.key;if(this.options.groupedColumns&&this.options.groupedColumns.length){ds.settings.groupby.defaultCollapseState=!this.options.initialExpand}if(this.options.type==="remote"){ds.dataBind()}else{if(ds.settings.sorting.expressions.length===0){if(layout){root=this.element.closest(".ui-iggrid-root");if(root&&root.data("igGridGroupBy")){gb=root.data("igGridGroupBy");cols=$.map(gb._orderedGroupedCols||[],function(e){return e.layout===layout});if(cols.length){return}}}ds._resetGroupByCollapseStates();this._saveCollapseStates();this.grid.dataBind()}else{ds.sort(ds.settings.sorting.expressions);this.grid._renderData()}}},_onKeyDownGroup:function(event){var $target;if(event.keyCode===$.ui.keyCode.ENTER||event.keyCode===$.ui.keyCode.SPACE){$target=$(event.target);this._toggleGroup(event);event.preventDefault();event.stopPropagation();$target.focus()}},_hidingFinishing:function(){this._colspan=null},_expandCollapseRow:function(rowId,exp,grid,$row){grid=grid||this.grid;var $scrCntnr,scrTop,avgRowHeight;this._scrolltop=$(window).scrollTop();if($row&&$row.length){if(!exp){$row.attr("data-state","collapsed").attr("aria-expanded","false").find(".ui-iggrid-expandbutton").attr("title",this._getLocaleValue("expandTooltip")).removeClass(this.css.groupByExpandCellExpanded).addClass(this.css.groupByExpandCellCollapsed)}else{$row.attr("data-state","expanded").attr("aria-expanded","true").find(".ui-iggrid-expandbutton").attr("title",this._getLocaleValue("collapseTooltip")).removeClass(this.css.groupByExpandCellCollapsed).addClass(this.css.groupByExpandCellExpanded)}}grid.container().find(".ui-iggrid-footer .ui-iggrid-results").data("overrideLabel",0);grid.dataSource.toggleGroupByRecord(rowId,!exp);if(grid.options.virtualization){avgRowHeight=grid._avgRowHeight;grid._avgRowHeight=null;grid._rerenderVirtualRecordsContinuous();grid._updateVirtualScrollContainer();grid._oldScrollTop=grid._scrollContainer().scrollTop();if(avgRowHeight>grid._avgRowHeight){grid._avgRowHeight=avgRowHeight;grid._updateVirtualScrollContainer()}}else{$scrCntnr=grid.scrollContainer();scrTop=$scrCntnr.scrollTop();grid._renderData();$scrCntnr.scrollTop(scrTop)}this.grid._adjustLastColumnWidth(false);this._saveCollapseStates(grid)},_toggleGroup:function(event){var parentrow=$(event.target).closest("tr"),grid,exp=parentrow.attr("data-state")!=="expanded";if(this._hierarchical){grid=parentrow.closest(".ui-iggrid-table").data("igGrid")}else{grid=this.grid}this._focusCellId=parentrow.attr("data-id");this._expandCollapseRow(parentrow.attr("data-id"),exp,grid,parentrow);event.stopPropagation()},_groupAreaList:function(){var area=$(".ui-iggrid-groupbyarea",this.grid.container()),layout,allgrouped=[],dropFunc,mousedownFunc,list=area.find("ul"),i,groupby=this,css,key,item,itemEdge,helperFunc,overFunc,outFunc,text;allgrouped=this.groupByColumns();if(list.length>0){list.empty()}else{list=$("<ul></ul>").appendTo(area).addClass("ui-iggrid-grouparealist")}helperFunc=function(event){var li=null;if($(event.target).is("li")){li=$(event.target)}else{li=$(event.target).closest("li")}li=li.clone();li.find(".ui-iggrid-groupbylabelrightedgeend").remove();li.find(".ui-iggrid-groupbylabelrightedge").remove();li.find(".ui-iggrid-groupbyremovebutton").remove();li.attr("data-dragging",true);return li};overFunc=function(event,ui){var $li;if(!ui.draggable.hasClass("ui-iggrid-groupedcolumnlabel")){return false}if(ui.draggable.attr("data-key")===$(this).attr("data-key")){return false}if(groupby._thOver){$li=ui.draggable.closest("ul").find("li[ data-key="+groupby._thOver+" ]");if($li.length>0&&$li.hasClass("ui-iggrid-groupbydroppableedge")){$li.removeClass("ui-iggrid-groupbydroppableedge")}}groupby._thOver=$(event.target).attr("data-key");$(event.target).addClass("ui-iggrid-groupbydroppableedge")};outFunc=function(event,ui){if(!ui.draggable.hasClass("ui-iggrid-groupedcolumnlabel")){return false}if(ui.draggable.attr("data-key")===$(this).attr("data-key")){return false}$(event.target).removeClass("ui-iggrid-groupbydroppableedge")};dropFunc=function(event,ui){var parent,$dragged,$target;$(this).removeClass("ui-iggrid-groupbydroppableedge");if(!ui.draggable.hasClass("ui-iggrid-groupedcolumnlabel")){return}if(ui.draggable.attr("data-key")!==$(this).attr("data-key")){parent=$(this).closest("ul");$target=$(this);$dragged=ui.draggable;if($dragged.index()>$target.index()){$dragged.insertBefore($target)}else{$dragged.insertAfter($target)}parent.find("li[ data-dragging=true ]").remove();parent.find("li").removeClass("ui-iggrid-groupbydroppableedge");groupby._regroup();groupby._groupAreaList();event.preventDefault();event.stopPropagation();return false}return};mousedownFunc=function(event){event.preventDefault();event.stopPropagation();return false};for(i=0;i<allgrouped.length;i++){key=allgrouped[i].key;layout=allgrouped[i].layout;text=allgrouped[i].col.headerText;if(allgrouped[i].dir==="asc"){css="ui-iggrid-asc ui-icon ui-icon-arrowthick-1-n"}else{css="ui-iggrid-desc ui-icon ui-icon-arrowthick-1-s"}item=$("<li></li>").appendTo(list).addClass(this.css.groupedColumnLabel).css("float","left").attr("data-key",key).attr("data-layout",layout||"").bind({mouseup:$.proxy(this._changeSortState,this)}).draggable({containment:"body",appendTo:"parent",distance:5,revert:"invalid",helper:helperFunc}).droppable({accept:"li",tolerance:"touch",over:overFunc,out:outFunc,drop:dropFunc});if(this.options.groupByLabelWidth!==null){item.width(this.options.groupByLabelWidth)}itemEdge=$("<span></span>").appendTo(item).css({"float":"right"}).addClass(this.css.groupedColumnLabel).addClass(this.css.groupedColumnLabelRightEdgeEnd);itemEdge.attr("data-marker","edge");item.prev().find("span[ data-marker ]").removeClass(this.css.groupedColumnLabelRightEdgeEnd).addClass(this.css.groupedColumnLabelRightEdge);if(layout){$("<span>"+text+"</span>").appendTo(item).addClass(this.css.groupedColumnLabelText);$("<span>"+layout+"</span>").prependTo(item).addClass(this.css.groupedColumnLayoutLabel)}else{$("<span>"+text+"</span>").appendTo(item)}$("<span></span>").appendTo(item).addClass(css);if(!$.ig.util.isTouch){$("<span></span>").appendTo(item).addClass("ui-iggrid-groupbyremovebutton").attr("data-localeid","removeButtonTooltip").attr("data-localeattr","title").attr("title",groupby._getLocaleValue("removeButtonTooltip")).bind({mouseup:$.proxy(groupby._removeButtonClick,groupby),mousedown:mousedownFunc})}if($.ig.util.isIE7&&item.width()>300){item.width(260)}else{item.width(Math.ceil(item.width())+22)}}list.children().bind({mouseover:$.proxy(this._showRemoveButton,this),mouseout:$.proxy(this._hideRemoveButton,this)})},_changeSortState:function(event){var li=$(event.target).closest("li"),key=li.attr("data-key"),i,layout=li.attr("data-layout"),layouts,eArgs,j,gc=this._orderedGroupedCols,s=this.grid.dataSource.settings.sorting.expressions,settings,lobj,noCancel;for(i=0;i<gc.length;i++){if(gc[i].key===key&&(layout&&layout===gc[i].layout||!layout)){if(gc[i].dir==="asc"){gc[i].dir="desc"}else{gc[i].dir="asc"}for(j=0;j<s.length;j++){if(s[j].fieldName===key&&(layout&&layout===s[j].layout||!layout)){s[j].dir=gc[i].dir;break}}eArgs={owner:this,groupedColumns:gc,key:gc[i].key,triggeredBy:"sortStateChanged"};noCancel=this._trigger(this.events.groupedColumnsChanging,event,eArgs);if(noCancel){this._rebind();this._trigger(this.events.groupedColumnsChanged,event,eArgs)}break}}if(layout){layouts=[];this._findLayout(layout,this.grid.options,layouts);lobj=layouts[0];for(i=0;lobj.features&&i<lobj.features.length;i++){if(lobj.features[i].name==="GroupBy"){settings=lobj.features[i].columnSettings;for(j=0;j<settings.length;j++){if(settings[j].columnKey===key){settings[j].dir=settings[j].dir==="asc"?"desc":"asc";break}}break}}}},_showRemoveButton:function(event){var button=$(event.target).closest("li").find(".ui-iggrid-groupbyremovebutton"),key=$(event.target).closest("li").attr("data-key"),layout=$(event.target).closest("li").attr("data-layout");if(!key){return}button.attr("data-key",key).attr("data-layout",layout).addClass("ui-icon ui-icon-circle-close")},_hideRemoveButton:function(event){var button=$(event.target).closest("li").find(".ui-iggrid-groupbyremovebutton");button.removeClass("ui-icon ui-icon-circle-close");$(event.target).closest("li").removeClass("ui-state-hover")},_removeButtonClick:function(event){var key=$(event.target).attr("data-key"),noCancel,layout,eArgs;if(this._isDragging){return}eArgs={owner:this,groupedColumns:this.options.groupedColumns,key:key,triggeredBy:"removeButton"};noCancel=this._trigger(this.events.groupedColumnsChanging,event,eArgs);if(noCancel){layout=$(event.target).attr("data-layout");this.ungroupByColumn(key,layout);this._trigger(this.events.groupedColumnsChanged,event,eArgs)}event.preventDefault();event.stopPropagation();return false},destroy:function(){var modalDialog=this._getModalDialog();this.grid.container().find(".ui-iggrid-groupbyarea").remove();this._removeInitCallbacks();if(this.grid._initialized&&!this.grid._destroyed){this.ungroupAll()}this._detachEvents(true);modalDialog[this.options.dialogWidget]("getCaptionButtonContainer");modalDialog.remove();this._removeOverridenFunctions();this._superApply(arguments);return this},_detachEvents:function(isDestroyDraggable){var ths=this.grid.headersTable().find("th"),i;if(isDestroyDraggable===true){for(i=0;i<ths.length;++i){if($(ths[i]).data().draggable){$(ths[i]).draggable("destroy")}}}ths.unbind("mouseover",this._headerMouseOverHandler).unbind("mouseout",this._headerMouseOutHandler);$(document).undelegate("#"+this.grid.id()+"_container td[ gbexpandcell=1 ]","mouseup",this._toggleGroupHandler);$(document).undelegate("#"+this.grid.id()+"_container td[ gbexpandcell=1 ]","keydown",this._onKeyDownGroupHandler);this.grid.element.unbind("iggridheaderrenderedinternal",this._headerRenderedHandler);this.grid.element.unbind("iggriddataempty",this._dataRenderingHandler);this.grid.element.unbind("iggrid_rowsrendering",this._rowsRenderingHandler);this.grid.element.unbind("iggridrowsrendered",this._rowsRenderedHandler);this.grid.element.unbind("iggridheadercellrendered",this._headerCellRenderedHandler);this.grid.element.unbind("iggridheadercelldragcancel",this._headerDragCancelHandler);this.grid.element.unbind("iggriduidirty",this._uiDirtyHandler);this.grid.element.unbind("iggriddatabound",this._dataBoundHandler);if(this._columnsCollectionModifiedHandler){this.grid.element.unbind("iggridcolumnscollectionmodified",this._columnsCollectionModifiedHandler)}if(isDestroyDraggable===true){delete this._dataRenderingHandler;delete this._rowsRenderingHandler;delete this._rowsRenderedHandler;delete this._headerCellRenderedHandler;delete this._headerDragCancelHandler;delete this._uiDirtyHandler;delete this._columnsCollectionModifiedHandler}},_initDefaultSettings:function(){var settings=[],key,cs=this.options.columnSettings,i,j,allowGroupBy,isToCheckUnboundColumns=this.grid._hasUnboundColumns===true&&this.options.type==="remote";this._orderedColumnSettings=[];if(this.grid.options.columns&&this.grid.options.columns.length>0){for(i=0;i<this.grid.options.columns.length;i++){allowGroupBy=true;if(isToCheckUnboundColumns&&this.grid.getUnboundColumnByKey(this.grid.options.columns[i].key)!==null){allowGroupBy=false}settings[i]={columnIndex:i,columnKey:this.grid.options.columns[i].key,allowGrouping:allowGroupBy,summaries:[],groupSummaries:null,isGroupBy:false}}}if(settings.length===0&&this.grid.options.autoGenerateColumns&&cs.length>0){for(i=0;i<cs.length;i++){if(!cs[i].columnKey){continue}if(!cs[i].dir){cs[i].dir=this.options.defaultSortingDirection||"asc"}this._orderedColumnSettings.push(cs[i])}}else{for(i=0;i<cs.length;i++){for(j=0;j<settings.length;j++){if(settings[j].columnKey===cs[i].columnKey||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"){settings[j][key]=cs[i][key]}}if(settings[j].dir===undefined&&this.options.defaultSortingDirection){settings[j].dir=this.options.defaultSortingDirection}this._orderedColumnSettings.push(settings[j])}}this.options.columnSettings=settings},_renderExtraFooterCells:function(row,colgroup,prepend){if(this.options.groupedColumns.length>0){if(prepend===true){$("<td></td>").addClass(this.css.footerExtraCell).prependTo(row).attr("data-skip",true)}else{$("<td></td>").addClass(this.css.footerExtraCell).appendTo(row).attr("data-skip",true)}}},_renderExtraHeaderCells:function(row,colgroup,prepend){if(this.options.groupedColumns.length>0){if(prepend===true){$("<td></td>").prependTo(row).addClass(this.css.headerExtraCell).attr("data-skip",true);if(colgroup){$("<col />").prependTo(colgroup).attr("data-skip",true).css("width",this.options.indentation)}}else{$("<td></td>").appendTo(row).addClass(this.css.headerExtraCell).attr("data-skip",true);if(colgroup){$("<col />").appendTo(colgroup).attr("data-skip",true).css("width",this.options.indentation)}}}},_addOrUpdateDataSkipCol:function(width){var $colgroup,attrs,$col,$htbl=this.grid.headersTable(),$ftbl=this.grid.footersTable();$colgroup=this.grid.element.children("colgroup");$col=$colgroup.children("[data-groupby-col]");if(!$col.length){attrs={"data-skip":"true","data-groupby-col":"true"};$("<col />").prependTo($colgroup).attr(attrs).width(width);if($htbl.attr("id")!==this.grid.element.attr("id")){$("<col />").prependTo($htbl.children("colgroup")).attr(attrs).width(width)}if($ftbl.attr("id")!==this.grid.element.attr("id")){$("<col />").prependTo($ftbl.children("colgroup")).attr(attrs).width(width)}}else{$col.width(width);$htbl.find(">colgroup>col[data-groupby-col]").width(width);$ftbl.find(">colgroup>col[data-groupby-col]").width(width)}},_columnsCollectionModified:function(event,args){if(args.owner.id()!==this.grid.id()){return}args.tbody=this.grid.element.children("tbody");if(this.options.groupedColumns.length>0){this._addOrUpdateDataSkipCol(this._indent);if(this.grid.options.width===null){this.grid._setContainerWidth(this.grid.container())}else{this.grid._updateGridContentWidth()}}this._dataEmpty(event,args)},_onUIDirty:function(){if(this.options.persist){return}this.ungroupAll()},_saveSortingExpressions:function(){if(this.options.persist){this.grid._savePersistenceData(this.grid.dataSource.settings.sorting.expressions,"sorting");this._groupedColumns=this._orderedGroupedCols;this._optionsGC=this.options.groupedColumns}this.grid._fireInternalEvent("_sortedColumnsChanging",this.grid.dataSource.settings.sorting.expressions)},_saveCollapseStates:function(grid){grid=grid||this.grid;grid._savePersistenceData(grid.dataSource._gbCollapsed,"gbCollapsed",grid.element[0].id)},_getSortingExpressions:function(){return this.grid._getPersistenceData("sorting")},_restoreGroupBy:function(){var se=this._getSortingExpressions(),col,layouts,lobj,i,key,nse=[];this.grid.dataSource._gbCollapsed=this.grid._getPersistenceData("gbCollapsed",this.grid.element[0].id);if(this._groupedColumns){this._orderedGroupedCols=this._groupedColumns}if(this._optionsGC){this.grid.dataSource.settings.sorting.expressions=se;this.grid.dataSource.settings.sorting.defaultFields=se;this.options.groupedColumns=this._optionsGC;if(this.grid._hasUnboundColumns&&this.options.type==="local"){nse=[];for(i=0;i<se.length;i++){if(se[i].layout){layouts=[];this._findLayout(se[i].layout,this.grid.options,layouts);lobj=layouts[0];col=this._getColumnByLayoutKey(se[i].fieldName,lobj.columns)}else{col=this.grid.columnByKey(se[i].fieldName)}if(col&&!col.unbound){nse.push(se[i])}}se=nse;this.grid.dataSource.settings.sorting.expressions=se;this.grid.dataSource.settings.sorting.defaultFields=se;for(i=0;i<this._optionsGC.length;i++){key=this._optionsGC[i].key;if(this._optionsGC[i].layout){layouts=[];this._findLayout(this._optionsGC[i].layout,this.grid.options,layouts);lobj=layouts[0];col=this._getColumnByLayoutKey(key,lobj.columns)}else{col=this.grid.columnByKey(key)}if(col&&col.unbound){this.ungroupByColumn(key,this._optionsGC[i].layout)}}}}if(se){this.grid.dataSource.settings.sorting.expressions=se;this.grid.dataSource.settings.sorting.defaultFields=se}},_onDataBound:function(){if(this.options.groupedColumns.length>0&&this.grid._isDataBoundCalled){this.grid._trigger("headerExtraCellsModified",null,{owner:this})}},_filterExpressionsByLayout:function(exprs,layout){exprs=exprs||[];layout=!layout||layout===""?null:layout;var i,len=exprs.length,res=[];for(i=0;i<len;i++){exprs[i].layout=exprs[i].layout===""?null:exprs[i].layout;if(exprs[i].layout===layout||!layout&&!exprs[i].layout){res.push(exprs[i])}}return res},_determineColspan:function(){if(this.grid._isMultiColumnGrid){this._colspan=this.grid.container().find("#"+this.grid.id()+" colgroup:first>col:not([ data-hiding ])").length-1}else{if(this.grid.options.showHeader){this._colspan=this.grid.headersTable().find("thead > tr:first").children("th:not(.ui-iggrid-expandheadercellgb)").length}else{this._colspan=this.grid.container().find("#"+this.grid.id()+" colgroup:first>col").length-1}}},_removeOverridenFunctions:function(){if(this._getDataViewHandler){this.grid._getDataView=this._getDataViewHandler}if(this._renderRecordsForVirtRowCountHandler){this.grid._renderRecordsForVirtRowCount=this._renderRecordsForVirtRowCountHandler}if(this._renderNewRowHandler){this.grid.renderNewRow=this._renderNewRowHandler}},_overrideFunctions:function(){if(!this._getDataViewHandler){this._getDataViewHandler=$.proxy(this.grid._getDataView,this.grid);this.grid._getDataView=$.proxy(this._getDataView,this)}if(!this._renderRecordsForVirtRowCountHandler){this._renderRecordsForVirtRowCountHandler=$.proxy(this.grid._renderRecordsForVirtRowCount,this.grid);this.grid._renderRecordsForVirtRowCount=$.proxy(this._renderRecordsForVirtRowCount,this)}if(!this._renderNewRowHandler){this._renderNewRowHandler=$.proxy(this.grid.renderNewRow,this.grid);this.grid.renderNewRow=$.proxy(this._renderNewRow,this)}},_renderRecordsForVirtRowCount:function(ds,rowNumber,rrFunc){var data=ds.slice(0,rowNumber),html;if(this.options.groupedColumns.length>0){if(this._colspan===undefined||this._colspan===null){this._determineColspan()}html=this._generateGroupByRowsMarkup(data,0,data.length-1)}else{html=this._renderRecordsForVirtRowCountHandler.call(this,ds,rowNumber,rrFunc)}return html},_getDataView:function(){if(this.options.groupedColumns.length>0){return this.grid.dataSource.groupByDataView()}return this._getDataViewHandler()},_removeInitCallbacks:function(){var i;for(i=0;this.grid._headerInitCallbacks&&i<this.grid._headerInitCallbacks.length;i++){if(this.grid._headerInitCallbacks[i].type==="GroupBy"){$.ig.removeFromArray(this.grid._headerInitCallbacks,i);break}}for(i=0;this.grid._footerInitCallbacks&&i<this.grid._footerInitCallbacks.length;i++){if(this.grid._footerInitCallbacks[i].type==="GroupBy"){$.ig.removeFromArray(this.grid._footerInitCallbacks,i);break}}},_addInitCallbacks:function(){this._removeInitCallbacks();this.grid._headerInitCallbacks.push({type:"GroupBy",func:$.proxy(this._renderExtraHeaderCells,this)});this.grid._footerInitCallbacks.push({type:"GroupBy",func:$.proxy(this._renderExtraFooterCells,this)})},_getDefaultSummaries:function(colType,defaultSummaries){var i,summaryFunctions=[];for(i=0;i<defaultSummaries.length;i++){if(defaultSummaries[i].active&&(defaultSummaries[i].dataType==="any"||defaultSummaries[i].dataType.indexOf(colType)!==-1)){summaryFunctions.push({summaryFunction:defaultSummaries[i].summaryFunction,label:defaultSummaries[i].label,summaryTemplate:"{label}{value}",applyFormat:defaultSummaries[i].applyFormat})}}return summaryFunctions},_getApplicableSummaries:function(colType,summaries,defaultSummaries){var i,defaultSummary,defaultSummarySetting,customSummarySetting,getDefaultSummaryByName,summaryFunctions=[];getDefaultSummaryByName=function(name){return defaultSummaries.filter(function(target){return target.name.toLowerCase()===name.toLowerCase()})};for(i=0;i<summaries.length;i++){if(typeof summaries[i].summaryFunction==="function"){customSummarySetting={summaryFunction:summaries[i].summaryFunction,label:"Custom = ",summaryTemplate:"{label}{value}",applyFormat:false};summaryFunctions.push($.extend(customSummarySetting,summaries[i]))}else if(typeof summaries[i].summaryFunction==="string"){defaultSummary=getDefaultSummaryByName(summaries[i].summaryFunction);if(!defaultSummary.length){customSummarySetting={label:"Custom = ",summaryTemplate:"{label}{value}",applyFormat:false};customSummarySetting=$.extend(customSummarySetting,summaries[i]);customSummarySetting.summaryFunction=window[summaries[i].summaryFunction];summaryFunctions.push(customSummarySetting)}else if(defaultSummary[0].dataType==="any"||defaultSummary[0].dataType.indexOf(colType)!==-1){defaultSummarySetting={label:defaultSummary[0].label,summaryTemplate:"{label}{value}",applyFormat:defaultSummary[0].applyFormat};defaultSummarySetting=$.extend(defaultSummarySetting,summaries[i]);defaultSummarySetting.summaryFunction=defaultSummary[0].summaryFunction;summaryFunctions.push(defaultSummarySetting)}}}return summaryFunctions},_generateSummariesSettings:function(){var i,columnDefault,columnSetting,summaries,resSummariesSettings,getColSettingsByKey,bEmptySummaries=true,cols=this.grid.options.columns,colSettings=this.options.columnSettings?this.options.columnSettings:[],defaultSummaries=$.ig.util.defaultSummaryMethods;defaultSummaries.sort(function(a,b){return a.order-b.order});resSummariesSettings={};for(i=0;i<cols.length;i++){columnDefault={groupSummaries:[]};if(this.options.groupSummaries===true){bEmptySummaries=false;summaries=this._getDefaultSummaries(cols[i].dataType,defaultSummaries);columnDefault.groupSummaries=summaries}else if($.isArray(this.options.groupSummaries)&&this.options.groupSummaries.length>0){bEmptySummaries=false;summaries=this._getApplicableSummaries(cols[i].dataType,this.options.groupSummaries,defaultSummaries);columnDefault.groupSummaries.push.apply(columnDefault.groupSummaries,summaries)}resSummariesSettings[cols[i].key]=columnDefault}getColSettingsByKey=function(colKey){return colSettings.filter(function(target){return target.columnKey===colKey})};for(i=0;i<cols.length;i++){columnSetting=getColSettingsByKey(cols[i].key);if(!columnSetting.length){continue}columnSetting=columnSetting[0];if(columnSetting.groupSummaries===true){bEmptySummaries=false;summaries=this._getDefaultSummaries(cols[i].dataType,defaultSummaries);resSummariesSettings[cols[i].key].groupSummaries=summaries}else if(columnSetting.groupSummaries===false){resSummariesSettings[cols[i].key].groupSummaries=[]}else if($.isArray(columnSetting.groupSummaries)&&columnSetting.groupSummaries.length>0){bEmptySummaries=false;summaries=this._getApplicableSummaries(cols[i].dataType,columnSetting.groupSummaries,defaultSummaries);resSummariesSettings[cols[i].key].groupSummaries=summaries}else if($.isArray(columnSetting.groupSummaries)){resSummariesSettings[cols[i].key].groupSummaries=[]}}for(i=0;i<this.options.columnSettings.length;i++){this.options.columnSettings[i].groupSummaries=resSummariesSettings[this.options.columnSettings[i].columnKey].groupSummaries}return bEmptySummaries},_initGroupSummaries:function(){var i,j,noSummaries,columnRes,colSettings,summariesRes=[],ds=this.grid.dataSource;noSummaries=this._generateSummariesSettings();if(noSummaries){return}colSettings=this.options.columnSettings;for(i=0;i<colSettings.length;i++){columnRes={field:colSettings[i].columnKey,summaryFunctions:[]};if(colSettings[i].groupSummaries&&colSettings[i].groupSummaries.length>0){for(j=0;j<colSettings[i].groupSummaries.length;j++){if(typeof colSettings[i].groupSummaries[j].summaryFunction==="string"){columnRes.summaryFunctions.push(colSettings[i].groupSummaries[j].summaryFunction)}else{columnRes.summaryFunctions.push(colSettings[i].groupSummaries[j].summaryFunction)}}}summariesRes.push(columnRes)}ds.settings.groupby.summaries=summariesRes;ds.settings.groupby.summariesPosition=this.options.groupSummariesPosition;if(this.grid.options.autoGenerateColumns){ds._generateGroupByData(ds._filter?ds._filteredData:ds._data,ds.settings.sorting.expressions)}},_injectGrid:function(gridInstance){var i,gc,gcsort,s,root=null,orderedGrouped=null,layoutGrouped=null;this.grid=gridInstance;this._checkGridNotSupportedFeatures();if(this.options.type===null){this.options.type=this.grid._inferOpType()}root=this.element.closest(".ui-iggrid-root");if(this.options.persist&&this.options.type==="remote"&&root.data("igGrid")){this.options.persist=false}if(root.is("div")){
root=root.find("#"+root.attr("id")+"_table")}root=root.data("igGridGroupBy");if(root){orderedGrouped=root._orderedGroupedCols;if(orderedGrouped&&orderedGrouped.length>0&&this.grid.options.key){layoutGrouped=[];for(i=0;i<orderedGrouped.length;i++){if(this.grid.options.key===orderedGrouped[i].layout){layoutGrouped.push(orderedGrouped[i])}}}}for(i=0;i<this.grid.options.features.length;i++){if(this.grid.options.features[i].name==="ColumnMoving"){this._movingEnabled=true;break}}this._dataBoundHandler=$.proxy(this._onDataBound,this);this._headerRenderedHandler=$.proxy(this._headerRendered,this);this._dataRenderingHandler=$.proxy(this._dataEmpty,this);this._toggleGroupHandler=$.proxy(this._toggleGroup,this);this._onKeyDownGroupHandler=$.proxy(this._onKeyDownGroup,this);this._rowsRenderingHandler=$.proxy(this._renderRecords,this);this._rowsRenderedHandler=$.proxy(this._recordsRendered,this);this._headerCellRenderedHandler=$.proxy(this._headerCellRendered,this);this._headerDragCancelHandler=$.proxy(this._headerCellDragCancel,this);this._detachEvents();this.grid.element.bind("iggridheaderrenderedinternal",this._headerRenderedHandler);this.grid.element.bind("iggriddataempty",this._dataRenderingHandler);this.grid.element.bind("iggrid_rowsrendering",this._rowsRenderingHandler);this.grid.element.bind("iggridrowsrendered",this._rowsRenderedHandler);this.grid.element.bind("iggridheadercellrendered",this._headerCellRenderedHandler);this.grid.element.bind("iggriddatabound",this._dataBoundHandler);this.grid.element.bind("iggridheadercelldragcancel",this._headerDragCancelHandler);this._headerMouseOverHandler=function(event){$(event.currentTarget).addClass("ui-state-hover")};this._headerMouseOutHandler=function(event){$(event.currentTarget).removeClass("ui-state-hover")};this._overrideFunctions();this.grid.dataSource.settings.sorting.sortUrlKey=this.options.groupByUrlKey;this.grid.dataSource.settings.sorting.sortUrlAscValueKey=this.options.groupByUrlKeyAscValue;this.grid.dataSource.settings.sorting.sortUrlDescValueKey=this.options.groupByUrlKeyDescValue;this.grid.dataSource.settings.sorting.enabled=true;this.grid.dataSource.settings.sorting.type=this.options.type||"remote";this.grid.dataSource.settings.encodeExtraParams=$.proxy(this._encodeSummaryParams,this);this.grid.dataSource.settings.groupby.defaultCollapseState=!this.options.initialExpand;this.grid.dataSource.settings.groupby.pagingMode=this.options.pagingMode;if(!this.grid._initialized){this._addInitCallbacks();this._initDefaultSettings();this.options.groupedColumns=[];if(!this.grid.options.key&&(layoutGrouped===null||layoutGrouped.length===0)){for(i=0;i<this._orderedColumnSettings.length;i++){if(this._orderedColumnSettings[i].isGroupBy){s=this._orderedColumnSettings[i];gc={key:s.columnKey,dir:s.dir||"asc",col:this.grid.columnByKey(s.columnKey)};this.options.groupedColumns.push(gc);gcsort={fieldName:s.columnKey,dir:s.dir||"asc",layout:this.grid.options.key||null,isGroupBy:true};if(this.options.type==="local"){this._addSortingExpression(this.grid.dataSource.settings.sorting.defaultFields,gcsort)}this._addSortingExpression(this.grid.dataSource.settings.sorting.expressions,gcsort)}}}else{for(i=0;layoutGrouped!==null&&i<layoutGrouped.length;i++){this.options.groupedColumns.push(layoutGrouped[i]);gcsort={fieldName:layoutGrouped[i].key,dir:layoutGrouped[i].dir||"asc",layout:this.grid.options.key||null,isGroupBy:true};if(this.options.type==="local"){this._addSortingExpression(this.grid.dataSource.settings.sorting.defaultFields,gcsort)}this._addSortingExpression(this.grid.dataSource.settings.sorting.expressions,gcsort)}}this._saveSortingExpressions()}this._initGroupSummaries();if(this.options.expansionIndicatorVisibility&&(this.grid.element.closest(".ui-iggrid-root").length===0||this.grid.element.hasClass("ui-iggrid-root")||this.grid._isWrapped)){$(document).delegate("#"+this.grid.id()+"_container td[ gbexpandcell=1 ]","mouseup",this._toggleGroupHandler);$(document).delegate("#"+this.grid.id()+"_container td[ gbexpandcell=1 ]","keydown",this._onKeyDownGroupHandler)}this._columnsCollectionModifiedHandler=$.proxy(this._columnsCollectionModified,this);this.grid.element.bind("iggridcolumnscollectionmodified",this._columnsCollectionModifiedHandler);this._uiDirtyHandler=$.proxy(this._onUIDirty,this);this.grid.element.bind("iggriduidirty",this._uiDirtyHandler);if(this.grid.element.igGridFeatureChooser!==undefined){this.grid.element.igGridFeatureChooser()}this._hierarchical=this.grid._isHierarchicalGrid;if(this.options.persist){this._restoreGroupBy()}this._indent=this.options.indentation;this._allGroupedCols(this._orderedGroupedCols)},_colgroupsRerendered:function(){if(this.options.groupedColumns.length>0){this._addOrUpdateDataSkipCol(this._indent)}},_checkGridNotSupportedFeatures:function(){var gridOptions=this.grid.options;if((gridOptions.virtualization===true||gridOptions.rowVirtualization===true||gridOptions.columnVirtualization===true)&&gridOptions.virtualizationMode==="fixed"){throw new Error(this._getLocaleValue("fixedVirualizationNotSupported"))}}});$.extend($.ui.igGridGroupBy,{version:"21.2.12"});return $});