/*!@license
* Infragistics.Web.ClientUI Outlook GroupBy feature 14.1.20141.1020
*
* Copyright (c) 2011-2014 Infragistics Inc.
*
* http://www.infragistics.com/
*
* Depends on:
*	jquery-1.4.4.js
*	jquery.ui.core.js
*	jquery.ui.widget.js
*	infragistics.ui.grid.framework.js
*	modernizr.js
*/
(function($){$.widget("ui.igGridGroupBy",{css:{dragMarkup:"ui-iggrid-dragMarkup",groupByArea:"ui-iggrid-groupbyarea",groupByAreaText:"ui-iggrid-groupbyareatext",groupedRow:"ui-iggrid-groupedrow",expandHeaderCellGroupBy:"ui-iggrid-expandheadercellgb ui-iggrid-header ui-widget-header",groupByExpandCellExpanded:"ui-icon ui-iggrid-expandbutton ui-iggrid-expandbuttonexpanded ui-icon-minus",groupByExpandCellCollapsed:"ui-icon ui-iggrid-expandbutton ui-icon-plus",groupByAreaDropHover:"ui-iggrid-groupbyareahover",groupByExpandColumn:"ui-iggrid-expandcolumn",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",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,emptyGroupByAreaContent:$.ig.GridGroupBy.locale.emptyGroupByAreaContent,emptyGroupByAreaContentSelectColumns:$.ig.GridGroupBy.locale.emptyGroupByAreaContentSelectColumns,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,groupComparerFunction:null,groupLabelFormatter:null,summaries:[{summaryFunction:"avg",text:null,customSummary:null}]}],expandTooltip:$.ig.GridGroupBy.locale.expandTooltip,collapseTooltip:$.ig.GridGroupBy.locale.collapseTooltip,removeButtonTooltip:$.ig.GridGroupBy.locale.removeButtonTooltip,featureChooserText:$.ig.GridGroupBy.locale.featureChooserText,featureChooserTextHide:$.ig.GridGroupBy.locale.featureChooserTextHide,modalDialogGroupByOnClick:false,modalDialogGroupByButtonText:$.ig.GridGroupBy.locale.modalDialogGroupByButtonText,modalDialogCaptionButtonDesc:$.ig.GridGroupBy.locale.modalDialogCaptionButtonDesc,modalDialogCaptionButtonAsc:$.ig.GridGroupBy.locale.modalDialogCaptionButtonAsc,modalDialogCaptionButtonUngroup:$.ig.GridGroupBy.locale.modalDialogCaptionButtonUngroup,modalDialogCaptionText:$.ig.GridGroupBy.locale.modalDialogCaptionText,modalDialogDropDownLabel:$.ig.GridGroupBy.locale.modalDialogDropDownLabel,modalDialogRootLevelHierarchicalGrid:$.ig.GridGroupBy.locale.modalDialogRootLevelHierarchicalGrid,modalDialogDropDownButtonCaption:$.ig.GridGroupBy.locale.modalDialogDropDownButtonCaption,modalDialogClearAllButtonLabel:$.ig.GridGroupBy.locale.modalDialogClearAllButtonLabel,emptyGroupByAreaContentSelectColumnsCaption:$.ig.GridGroupBy.locale.emptyGroupByAreaContentSelectColumnsCaption,modalDialogDropDownWidth:200,modalDialogDropDownAreaWidth:null,modalDialogAnimationDuration:200,modalDialogWidth:400,modalDialogHeight:"",modalDialogButtonApplyText:$.ig.GridGroupBy.locale.modalDialogButtonApplyText,modalDialogButtonCancelText:$.ig.GridGroupBy.locale.modalDialogButtonCancelText,useGridColumnFormatter:true,persist:true},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(options,element){this.options.columnSettings=[];this.options.groupedColumns=[];this._tempSortingExpr=[];this._tempGroupedColumns=[];this._tempOrderedGroupedCols=[];this._tempOptions={};this._currentTreeLayer=null;this._isInitFC=false;this._modalSelectedLayout=null;$.Widget.prototype._createWidget.apply(this,arguments)},_setOption:function(key,value){var modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog");$.Widget.prototype._setOption.apply(this,arguments);if(key==="groupByAreaVisibility"||key==="expansionIndicatorVisibility"){throw new Error($.ig.Grid.locale.optionChangeNotSupported+" "+key)}switch(key){case"modalDialogGroupByOnClick":$("#"+this.grid.id()+"_groupby_modalDialog").remove();this._renderGroupByDialog();break;case"modalDialogCaptionText":modalDialog.igGridModalDialog("option","modalDialogCaptionText",value);break;case"modalDialogAnimationDuration":modalDialog.igGridModalDialog("option","animationDuration",value);break;case"modalDialogWidth":modalDialog.igGridModalDialog("option","modalDialogWidth",value);break;case"modalDialogHeight":modalDialog.igGridModalDialog("option","modalDialogHeight",value);break;case"modalDialogButtonApplyText":modalDialog.igGridModalDialog("option","buttonApplyText",value);break;case"modalDialogButtonCancelText":modalDialog.igGridModalDialog("option","buttonCancelText",value);break;default:break}},_headerRendered:function(event,args){var groupby=this,groupbyarea;if(args.owner.id()!==this.grid.id()){return}if(args.owner.element.attr("data-childgrid")){return}if(this.options.groupByAreaVisibility==="top"){groupbyarea=$("<div></div>").prependTo(this.grid.container())}else if(this.options.groupByAreaVisibility==="bottom"){groupbyarea=$("<div></div>").appendTo(args.owner.container())}else if(this.options.groupByAreaVisibility==="hidden"){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")}this._renderGroupByDialog()},_renderGroupByDialog:function(){var $buttonOK,self=this,o=this.options,$captionButtonContainer,modalDialog=$("<div></div>").appendTo(this.grid._rootContainer()).attr("id",this.grid.id()+"_groupby_modalDialog");modalDialog.igGridModalDialog({renderFooterButtons:!o.modalDialogGroupByOnClick,modalDialogCaptionText:o.modalDialogCaptionText,modalDialogWidth:o.modalDialogWidth,modalDialogHeight:o.modalDialogHeight,animationDuration:o.modalDialogAnimationDuration,buttonApplyText:o.modalDialogButtonApplyText,buttonCancelText:o.modalDialogButtonCancelText,gridContainer:this.grid.container(),modalDialogOpening:function(event,args){self._groupByDialogOpening(event,args)},modalDialogMoving:function(e,ui){self._trigger(self.events.modalDialogMoving,null,{modalDialogElement:e.target,owner:self,originalPosition:ui.originalPosition,position:ui.position})},modalDialogClosing:function(event,args){return self._trigger(self.events.modalDialogClosing,null,{modalDialogElement:modalDialog,owner:self})},modalDialogClosed:function(event,args){self._trigger(self.events.modalDialogClosed,null,{modalDialogElement:modalDialog,owner:self})}});if(o.modalDialogGroupByOnClick){$captionButtonContainer=modalDialog.igGridModalDialog("getCaptionButtonContainer");$("<span></span>").bind("click.hiding",function(event){modalDialog.igGridModalDialog("closeModalDialog",true);event.preventDefault();event.stopPropagation();return false}).addClass("ui-icon ui-icon-closethick").appendTo($("<a></a>").appendTo($captionButtonContainer).attr("title",$.ig.GridHiding.locale.columnChooserCloseButtonTooltip).attr("href","#").attr("role","button").addClass("ui-dialog-titlebar-close ui-corner-all"))}else{$captionButtonContainer=modalDialog.igGridModalDialog("getCaptionButtonContainer");$buttonOK=$("#"+this.grid.id()+"_groupby_modalDialog_footer_buttonok");$buttonOK.bind("igbuttonclick",function(e){self._groupByDialogButtonOKClick(e)})}},openGroupByDialog:function(){var modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog");modalDialog.igGridModalDialog("openModalDialog")},closeGroupByDialog:function(){var modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog");modalDialog.igGridModalDialog("closeModalDialog")},_groupByDialogOpening:function(){var noCancel,modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog");noCancel=this._trigger(this.events.modalDialogOpening,null,{modalDialogElement:modalDialog,owner:this});if(noCancel){this.renderGroupByModalDialog();this._trigger(this.events.modalDialogOpened,null,{modalDialogElement:modalDialog,owner:this})}},renderGroupByModalDialog:function(){var $content,i,self=this,o=this.options,css=this.css,modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog"),noCancel,$groupedColumns,$ungroupedColumns;noCancel=this._trigger(this.events.modalDialogContentsRendering,null,{modalDialogElement:modalDialog,owner:this});if(noCancel){$content=modalDialog.igGridModalDialog("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.id()+"_groupbydialog_reset_button").remove()}this._trigger(this.events.modalDialogContentsRendered,null,{modalDialogElement:modalDialog,owner:this})}},_addSlideButtonGroupedColumns:function(){var css=this.css,o=this.options,$groupedColumns=$("#"+this.grid.id()+"_groupby_modalDialog_groupedcolumns"),buttonId=this.grid.id()+"_groupbymodaldialot_slidebutton",$button,innerHTML;innerHTML='<div class="'+css.dialogSlideArea+'">'+'	<div class="'+css.dialogSlideAreaContainer+'">'+'		<button id="'+buttonId+'" class="'+css.dialogButtonSlide+'" role="button" aria-disabled="false" title="'+o.dialogButtonSlideCaption+'">'+'			<span class="'+css.dialogButtonSlideContainer+'"></span>'+'			<span class="ui-button-text">'+o.dialogButtonSlideCaption+"</span>"+"		</button>"+"	</div>"+"</div>";$(innerHTML).insertAfter($groupedColumns);$button=$("#"+buttonId);$button.bind({click:function(e,args){$groupedColumns.slideToggle("slow");$(this).find("span:eq(0)").toggleClass(css.dialogButtonSlideUp);return false}})},_renderLayoutsDropDown:function(){var o=this.options,fn,self=this,css=this.css,modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog"),$content=modalDialog.igGridModalDialog("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;">'+o.modalDialogDropDownLabel+"</div>"+'<div class="'+css.dialogLayoutsDD+'">'+'	<div id="'+this.grid.id()+'_groupby_modalDialog_layoutsDDField" class="'+css.dialogLayoutsDDField+'">'+o.modalDialogRootLevelHierarchicalGrid+"</div>"+'	<span id="'+this.grid.id()+'_groupby_modalDialog_layoutsDDButton" style="float:right;">^</span>'+'	<div style="clear: both;"></div>'+"</div>"+'<div style="clear: both;"></div>';$layoutsContainer.html(htmlLayouts);$buttonDD=$("#"+this.grid.id()+"_groupby_modalDialog_layoutsDDButton");$buttonDD.wrap('<a href="#" title="'+o.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=$("#"+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.id()+"_groupby_modalDialog_content")).bind({click:function(e,args){clearTimeout(self._dropDownTimeout);setTimeout(function(){$buttonDD.closest("a").focus()},10)}});if(o.modalDialogDropDownWidth){$buttonDD.closest("div").width(o.modalDialogDropDownWidth)}if(modalDialogDropDownAreaWidth){$dropDown.width(modalDialogDropDownAreaWidth)}$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",dataSource:columnLayoutsData,initialExpandDepth:1e6,bindings:{textKey:"key",childDataProperty:"columnLayouts"},nodeClick:function(event,args){var data=args.node.data,keyLayout=data.key,$groupedUL=$("#"+self.grid.id()+"_groupby_modalDialog_groupedcolumns ul"),$ungroupedUL=$("#"+self.grid.id()+"_groupby_modalDialog_ungroupedcolumns ul");if(data.dislabledGroupBy===true){return}$groupedUL.empty();$ungroupedUL.empty();$("#"+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.id()+"_groupby_modalDialog_layoutsDD");if($dropDown.is(":visible")===false){this._toggleDropDown()}},closeDropDown:function(){var $dropDown=$("#"+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.id()+"_groupby_modalDialog_layoutsDDButton").parent(),$modalDialogContent=$("#"+this.grid.id()+"_groupby_modalDialog_content"),$layoutsDDField=$("#"+this.grid.id()+"_groupby_modalDialog_layoutsDDField").parent(),left=0,top=0,$dropDown=$("#"+this.grid.id()+"_groupby_modalDialog_layoutsDD"),isVisible=$dropDown.is(":visible")===true,self=this;if($dropDown.data("isAnimating")===true){return}if(!isVisible){top=$layoutsDDField.offset().top-$modalDialogContent.offset().top+$layoutsDDField.height()+1;left=$layoutsDDField.offset().left-$modalDialogContent.offset().left;$dropDown.css({top:top,left:left})}$dropDown.data("isAnimating",true);$dropDown.slideToggle(400,function(){var $layoutsDD=$("#"+self.grid.id()+"_groupby_modalDialog_layoutsDD"),$tree=$("#"+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,args){var noCancel,o=this.options,modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog"),i,j,len,tempGroupedCol,isToCallGroupedColumnsChanged=false,copy;noCancel=this._trigger(this.events.modalDialogButtonApplyClick,null,{modalDialogElement:modalDialog,owner:this,groupedColumns:this._tempGroupedColumns,groupedColumnLayouts:this._tempOptions.columnLayouts,sortingExpr:this._tempSortingExpr});if(noCancel){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}}}if(isToCallGroupedColumnsChanged===true){this._trigger(this.events.groupedColumnsChanged,e,{owner:this,groupedColumns:this._tempGroupedColumns})}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._tempSortingExpr}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}if(o.groupedColumns.length===0&&this.grid.headersTable().find("thead tr").children().first().hasClass("ui-iggrid-expandheadercellgb")){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()}copy=this._orderedGroupedCols.slice(0);this._orderedGroupedCols=[];this._ensureLabelsOrder(copy,this._orderedGroupedCols,this.grid.options);this._rebind();if(this.grid.options.width!==null&&this.grid.options.width!==undefined){this.grid._updateGridContentWidth()}this.grid._trigger("headerExtraCellsModified",null,{owner:this});e.preventDefault();e.stopPropagation();modalDialog.igGridModalDialog("closeModalDialog")}},_setSortingTempExpr:function(key,dir,layout){var i,layouts,j,gc=this._tempGroupedColumns,gcTemp,sexpr,s=this._tempSortingExpr,settings,lobj;sexpr={fieldName:key,dir:dir,layout:layout,isGroupBy:true};if(dir===""){for(j=0;j<s.length;j++){if(s[j].fieldName===key&&s[j].layout===layout){s.splice(j,1);break}}return}if(gc.length===0&&!layout){gcTemp=this._tempGroupedColumns.slice(0);this._allGroupedCols(gcTemp);gc=gcTemp.slice(0)}for(i=0;i<gc.length;i++){if(gc[i].key===key){gc[i].dir=dir;for(j=0;j<s.length;j++){if(s[j].fieldName===key){s[j].dir=gc[i].dir;if(gc[i].layout){s[j].layout=gc[i].layout}break}}if(j===s.length){this._addSortingExpressions(s,sexpr)}break}}if(layout){for(i=0;i<this._tempOrderedGroupedCols.length;i++){if(this._tempOrderedGroupedCols[i].key===key&&(this._tempOrderedGroupedCols.layout&&this._tempOrderedGroupedCols.layout===layout||!this._tempOrderedGroupedCols.layout)){this._tempOrderedGroupedCols[i].dir=dir;break}}for(j=0;j<s.length;j++){if(s[j].fieldName===key&&s[j].layout===layout){s[j].dir=dir;break}}if(j===s.length){this._addSortingExpressions(s,sexpr)}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};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=[];if(this.grid._isMultiColumnGrid){this._getAllColumns(columns,columnsRes)}else{columnsRes=columns}$.each(columnsRes,function(columnIndex,column){var cs=self._findColumnSetting(column.key);if(self.options.type==="remote"&&(column.unboundDS===true||column.unbound===true)){return true}if(!cs||cs.allowGrouping){if(self._checkColumnIsGroupedInternal(column.key,layout,self._tempGroupedColumns,self._tempOptions)){self._renderDialogGroupedColumn(column,layout)}else{self._renderDialogUngroupedColumn(column,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===true){return true}if(this._tempGroupedColumns.length>0){return true}if(this._checkRenderLayoutsClearAll(this.grid.options)===true){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.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.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){dir=s[j].dir;break}}}$li=$("<li></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="'+o.modalDialogCaptionButtonAsc+'">'+'	<span class="'+css.dialogButtonAscIcon+'"></span>'+"</span>"+'<span class="'+css.dialogGroupedColumnTextContainer+'">'+column.headerText+"</span>"+'<button id="'+buttonUngroupId+'" class="'+css.dialogButtonUngroup+'" role="button" title="'+o.modalDialogCaptionButtonUngroup+'" >'+'	<span class="'+css.dialogButtonUngroupContainer+'"></span>'+'	<span class="ui-button-text">'+o.modalDialogCaptionButtonUngroup+"</span>"+"</button>";$li.html(liHTML);$buttonUngroup=$("#"+buttonUngroupId);self._setDialogButtonAscDesc(dir==="asc",key);$li.bind({click:function(e,args){self._dialogButtonAscDescClick(key,layout)}});$buttonUngroup.bind({click:function(e,args){var noCancel;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)}self._renderDialogUngroupedColumn(column,layout);if($("#"+self.grid.id()+"_groupby_modalDialog_groupedcolumns ul li").length===0&&self._isToRenderClearAllButton()===false){$("#"+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(e,args){if(!$(this).hasClass(css.dialogButtonsHover)){$(this).addClass(css.dialogButtonsHover)}},mouseout:function(e,args){if($(this).hasClass(css.dialogButtonsHover)){$(this).removeClass(css.dialogButtonsHover)}}})},_dialogButtonAscDescClick:function(key,layout){var o=this.options,$buttonAscDesc=$("#"+this.grid.id()+"_"+key+"_groupbydialog_groupedcolumns_buttonascdesc"),noCancel,modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog"),isAsc=$buttonAscDesc.data("isAsc");noCancel=this._trigger(this.events.modalDialogSortGroupedColumn,null,{modalDialogElement:modalDialog,owner:this,key:key,isAsc:!isAsc,layout:layout});if(noCancel){if(isAsc===true){if(o.modalDialogGroupByOnClick===true){this._setSortingTempExpr(key,"desc",layout);this.grid.dataSource.settings.sorting.expressions=this._tempSortingExpr;this._rebind()}else{this._setSortingTempExpr(key,"desc",layout)}}else{if(o.modalDialogGroupByOnClick===true){this._setSortingTempExpr(key,"asc",layout);this.grid.dataSource.settings.sorting.expressions=this._tempSortingExpr;this._rebind()}else{this._setSortingTempExpr(key,"asc",layout)}}this._setDialogButtonAscDesc(!isAsc,key)}},_setDialogButtonAscDesc:function(isAsc,key){var css=this.css,$buttonAscDesc=$("#"+this.grid.id()+"_"+key+"_groupbydialog_groupedcolumns_buttonascdesc"),$spanIcon=$buttonAscDesc.find("span:eq(0)"),caption;if(isAsc===true){$buttonAscDesc.removeClass(css.dialogButtonDesc).addClass(css.dialogButtonAsc);$spanIcon.removeClass(css.dialogButtonDescIcon).addClass(css.dialogButtonAscIcon);caption=this.options.modalDialogCaptionButtonAsc}else{$buttonAscDesc.removeClass(css.dialogButtonAsc).addClass(css.dialogButtonDesc);
$spanIcon.removeClass(css.dialogButtonAscIcon).addClass(css.dialogButtonDescIcon);caption=this.options.modalDialogCaptionButtonDesc}$buttonAscDesc.data("isAsc",isAsc).attr("title",caption)},_renderDialogButtonClearAll:function(){if(this.options.modalDialogGroupByOnClick===true){return}var self=this,o=this.options,resetButtonId=self.grid.id()+"_groupbydialog_reset_button",modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog"),$captionButtonContainer,$resetButton;if($("#"+resetButtonId).length===0){$captionButtonContainer=modalDialog.igGridModalDialog("getCaptionButtonContainer");$resetButton=$("<button></button>").attr("id",resetButtonId).appendTo($captionButtonContainer);$resetButton.igButton({labelText:o.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.id()+"_groupby_modalDialog_groupedcolumns ul");$ungroupedUL=$("#"+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.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(o.modalDialogGroupByButtonText);$li.bind({click:function(e,args){var noCancel;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();self._renderDialogGroupedColumn(column,layout);self._renderDialogButtonClearAll();self._trigger(self.events.modalDialogGroupColumn,e,{key:key,layout:layout,owner:self,groupedColumns:self._tempGroupedColumns})}e.preventDefault();e.stopPropagation()}})},_setGroupAreaTextContent:function($area){var text=this.options.emptyGroupByAreaContent,linkText=this.options.emptyGroupByAreaContentSelectColumns,linkTextCaption=this.options.emptyGroupByAreaContentSelectColumnsCaption,$a,self=this;text=text.replace("{0}",'<a href="#" id="'+this.grid.id()+'_link_selectcolumns" title="'+linkTextCaption+'">'+linkText+"</a>");$area.html(text);$a=$("#"+this.grid.id()+"_link_selectcolumns");$a.bind({click:function(e,args){self.openGroupByDialog();e.preventDefault();e.stopPropagation()}})},_headerCellDragCancel:function(event,args){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._findColumnSetting(args.columnKey);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",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(event,ui){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"))}}},_findColumnSetting: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._getTotalRowCountHandler){this.grid._getTotalRowCount=this._getTotalRowCountHandler;this._getTotalRowCountHandler=null}if(this.options.groupedColumns.length>0){this._renderRecordsInternal()}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)}},_renderRecordsInternal:function(){var grid=this.grid,idval=null,ds=grid.dataSource.dataView(),firstTime=true,counter,d=[],tbody=grid.element.children("tbody"),fh=false,html,i,tbodyHtml,$thDataSkip,gr,groupedRowsLength,tr,countHiddenRows;this._indent=this.options.indentation;if(this.grid.options.fixedHeaders===true){fh=true}if(this.grid._isMultiColumnGrid){this._colspan=this.grid.container().find("#"+this.grid.id()+" colgroup:first>col").length-1}else{if(this.grid.options.showHeader){this._colspan=this.grid.container().find("#"+this.grid.id()+(fh===true?"_headers":"")+" 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}}this._processGroupsRecursive(0,ds,tbody,d,idval,0,ds.length,firstTime);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).attr("data-skip",true);if(grid._isMultiColumnGrid){$thDataSkip.attr("rowspan",grid._maxLevel+1)}if(grid.headersTable().attr("id")!==grid.element.attr("id")){$("<col />").prependTo(grid.headersTable().find("colgroup")).attr("data-skip","true").width(this._indent)}if(grid.footersTable().attr("id")!==grid.element.attr("id")){$("<col />").prependTo(grid.footersTable().find("colgroup")).attr("data-skip","true").width(this._indent)}}else{grid.headersTable().find("colgroup col:nth-child(1)").width(this._indent);grid.footersTable().find("colgroup col:nth-child(1)").width(this._indent)}tbody.show();html=d.join("");if(grid.options.virtualization===true){this.grid._scrollTo(0,true);this._groupedRows=this._tokenizeTBody(html);if(this._groupedRows.length>0){this._groupedRows[0]=this._groupedRows[0].substr(0,3)+' data-firstgrouprow="true" '+this._groupedRows[0].substr(3);this._groupedRows[this._groupedRows.length-1]=this._groupedRows[this._groupedRows.length-1].substr(0,3)+' data-lastrow="true" '+this._groupedRows[this._groupedRows.length-1].substr(3);for(i=this._groupedRows.length-1;i>=0;i--){if(this._groupedRows[i].indexOf('data-grouprow="true"')>=0){this._groupedRows[i]=this._groupedRows[i].substr(0,3)+' data-lastgrouprow="true" '+this._groupedRows[i].substr(3);break}}this._virtualRowCount=this._determineVirtualRowCount(this._groupedRows,grid._getDisplayContainerHeight());if(this._virtualRowCount>this._groupedRows.length){this._virtualRowCount=this._groupedRows.length}tbodyHtml="";if(!this.options.initialExpand){if(!this._getTotalRowCountHandler){this._getTotalRowCountHandler=$.proxy(grid._getTotalRowCount,grid);grid._getTotalRowCount=$.proxy(this._getTotalRowCount,this)}this._countGroupedRows=html.match(/(data-grouprow="true")/gi).length;this._cachedGroupedRows=this._groupedRows;gr=[];this._groups={};counter=0;groupedRowsLength=this._groupedRows.length;countHiddenRows=0;for(i=0;i<groupedRowsLength;i++){tr=this._groupedRows[i];if(tr.indexOf("data-grouprow")>-1){counter++;countHiddenRows=0;tr=tr.replace(/data-row-idx="(\d)+"/i,'data-row-idx="'+(counter-1)+'"');gr.push(tr)}else{if(++countHiddenRows>this._virtualRowCount){continue}if(!this._groups[counter-1]){this._groups[counter-1]=[]}this._groups[counter-1].push(tr)}}this._groupedRows=gr;gr=null;if(this._virtualRowCount>this._groupedRows.length){this._virtualRowCount=this._groupedRows.length}for(i=0;i<this._virtualRowCount;i++){tbodyHtml+=this._groupedRows[i]}}else{for(i=0;i<this._virtualRowCount;i++){tbodyHtml+=this._groupedRows[i]}}if(window.MSApp===undefined){tbody.html(tbodyHtml)}else{MSApp.execUnsafeLocalFunction(function(){tbody.html(tbodyHtml)})}this.grid._buildVirtualDomForContinuousVirtualization()}}else{if(window.MSApp===undefined){tbody.html(html)}else{MSApp.execUnsafeLocalFunction(function(){tbody.html(html)})}if(this.grid.options.width===null){this.grid._setContainerWidth(this.grid.container())}else{this.grid._updateGridContentWidth()}}this._avgRowHeight=this.grid._calculateAvgRowHeight();this.grid._trigger(this.grid.events.rowsRendered,null,{owner:this.grid,tbody:tbody})},_getTotalRowCount:function(){if(this.options.groupedColumns.length>0){return this._countGroupedRows}return this._getTotalRowCountHandler()},_processGroupsRecursive:function(i,ds,tbody,d,idval,start,end,firstTime){var index,tmpSum=0,j,tmpCount=start,tmpStart=start,k,arr,arrLength,cssClass,gcval=this.options.groupedColumns[i].key,cs;if(ds.length===0){return}idval=ds[tmpCount][gcval];cs=this._settingFromKey(gcval);firstTime=true;if(!(this.options.indentation&&this.options.indentation.indexOf&&this.options.indentation.indexOf("%")!==-1)){this._indent=parseInt(this.options.indentation,10)*(i+1)}for(j=start;j<end;j++){if(j<tmpCount||tmpCount>=end){continue}if(!this._cmp(cs,ds[tmpCount][gcval],idval)||firstTime){firstTime=false;idval=ds[tmpCount][gcval];if(cs.customGroupName){index=this._renderGroupRow(d,i,gcval,idval,cs.customGroupName,cs,ds[tmpCount])}else{index=this._renderGroupRow(d,i,gcval,idval,null,cs,ds[tmpCount])}tmpStart=tmpCount;if(this.options.groupedColumns.length-1>i){while(tmpCount<end&&this._cmp(cs,ds[tmpCount][gcval],idval)){tmpCount++;tmpSum++}this._rs(gcval,idval,index,tmpSum,tmpStart,tmpCount,ds,d);tmpSum=0;this._processGroupsRecursive(i+1,ds,tbody,d,idval,j,tmpCount,firstTime)}else{arr=[];while(tmpCount<end&&this._cmp(cs,ds[tmpCount][gcval],idval)){tmpCount++;tmpSum++;this._renderRecord(d,tbody,ds[tmpCount-1],tmpCount-1,this.options.initialExpand,arr)}arrLength=arr.length;for(k=0;k<arrLength;k++){cssClass=this.css.nonGroupRowEmptyCell;if(k===arrLength-1){cssClass+=" "+this.css.groupByLastEmptyCell}d[arr[k]]+='<td class="'+cssClass+'" data-skip="true"></td>'}this._rs(gcval,idval,index,tmpSum,tmpStart,tmpCount,ds,d);tmpSum=0}}}},_rs:function(gcval,idval,index,tmpSum,tmpStart,tmpCount,ds,d){var subdata;tmpSum=this._calcRealSum(gcval,idval,tmpSum,ds);d[index]=d[index].replace("__sum__",tmpSum);if(d[index].indexOf("$$value$$")!==-1){subdata=ds.slice(tmpStart,tmpCount);d[index]=this._calcRealSummary(d[index],gcval,idval,subdata)}},_cmp:function(cs,val1,val2){var res,o=this.grid.options,enableUTCDates=o.enableUTCDates,rowTemplate=!o.rowTemplate||o.rowTemplate.length<=0,format,key,col;if(cs.groupComparerFunction){if(typeof cs.groupComparerFunction==="function"){res=cs.groupComparerFunction(cs,val1,val2)}else{res=window[cs.groupComparerFunction](cs,val1,val2)}return res}if($.type(val1)==="date"&&$.type(val2)==="date"){key=cs.columnKey;if(key!==undefined&&key!==null){col=this.grid.columnByKey(key);if(col!==undefined&&col!==null){format=col.format}}return $.ig.formatter(val1,"date",format,rowTemplate,enableUTCDates)===$.ig.formatter(val2,"date",format,rowTemplate,enableUTCDates)}return val1===val2},_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}}}}},_calcRealSummary:function(contents,gcval,idval,subdata){var n,k,i,cs,j,mdata=this.grid.dataSource.metadata(this.options.resultResponseKey),o,str=contents,val,found=false,mul=1,t,k_val;n=this.grid.dataSource.data();if(mdata&&mdata!==null){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"){k_val=k.toLowerCase()==="true"?true:false}else if(t==="number"&&$.type(k)==="string"){k_val=mul*k}else{k_val=k}if(idval!==null&&!idval.length&&idval===k_val*mul||k_val===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.dataSource.dataView().length<n.length){return this._summaries(str,subdata,gcval)}},_calcRealSum:function(gcval,idval,sum,ds){var tmpSum=0,k,n,nLen,setting,mul=1,idx,metadata,t,n_val;setting=this._settingFromKey(gcval);metadata=this.grid.dataSource.metadata(this.options.resultResponseKey);if(metadata&&metadata[gcval]){k=metadata[gcval];for(n in k){if(k.hasOwnProperty(n)){t=this.grid.columnByKey(gcval).dataType;if(t==="bool"&&$.type(n)==="string"){n_val=n.toLowerCase()==="true"?true:false}else if(t==="number"&&$.type(n)==="string"){n_val=mul*n}else{n_val=n}if(idval!==null&&idval!==undefined&&!idval.length&&idval===n_val*mul){tmpSum=k[n]}else if(n_val===idval){tmpSum=k[n]}}}}else if(ds.length<this.grid.dataSource.data().length){tmpSum=0;if(this.grid.dataSource._filter&&this.grid.dataSource._filteredData&&this.options.type==="local"){n=this.grid.dataSource._filteredData}else{n=this.grid.dataSource.data()}nLen=n.length;for(k=0;k<nLen;k++){if(this._cmp(setting,n[k][gcval],idval)){idx=k;break}}for(k=idx;k<nLen;k++){if(this._cmp(setting,n[k][gcval],idval)){tmpSum++}else{break}}}return tmpSum>0?tmpSum:sum},_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(arr,indent,field,val,customName,colCustomSetting,record){var expcell,textcell,col,margin=indent>0?parseInt(this.options.indentation,10)*indent:0,text,state,css,i,cs=this.options.columnSettings,shtml="",tmpl,title,j,hide=false;if(this.options.initialExpand){css=this.css.groupByExpandCellExpanded;title=this.options.collapseTooltip}else{css=this.css.groupByExpandCellCollapsed;title=this.options.expandTooltip;if(indent>0){hide=true}}if(this.options.expansionIndicatorVisibility){expcell='<td class="'+this.css.groupByExpandColumn+'" gbexpandcell="1"><span class="ui-iggrid-expandbuttoncontainer-group-by" style="margin-left:'+margin+'px;"><span class="'+css+'" title="'+title+'"></span></span></td>'}else{expcell='<td class="'+this.css.groupByExpandColumn+'" 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,record," ")}tmpl=tmpl.replace("${key}",col.headerText);if(customName){text=tmpl.replace("${val}",customName).replace("${count}","__sum__")}else{text=tmpl.replace("${val}",val).replace("${count}","__sum__")}if(this.options.initialExpand){state="expanded"}else{state="collapsed"}for(i=0;i<cs.length;i++){for(j=0;j<cs[i].summaries.length;j++){shtml+=" "+cs[i].columnKey+" "+(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 colspan="'+this._colspan+'">'+text+"</td>";arr.push('<tr class="'+this.grid.css.recordClass+" "+this.css.groupedRow+'" data-grouprow="true" data-state="'+state+'" data-glevel="'+indent+'"'+(hide?' style="display:none;"':"")+">"+expcell+textcell+"</tr>");return arr.length-1},_renderRecord:function(d,tbody,data,rowIndex,expand,arr){var i,j,dLen,lastIndex=d.length;this.grid._renderRecordInArray(d,tbody,data,rowIndex);dLen=d.length;for(i=lastIndex;i<dLen;i++){if(d[i].indexOf&&d[i].indexOf("<tr")!==-1){if(!expand){d[i]=d[i]+' style="display: none;"'}for(j=i;j<dLen;j++){if(d[j].indexOf&&d[j].indexOf("data-grouprow")!==-1){break}if(d[j].indexOf&&d[j].indexOf(">")!==-1){arr.push(j);break}}break}}},_renderNewRow:function(rec,key){var tbody=this.grid.element.children("tbody"),dataRows=tbody.children("tr:not([data-container='true'],[data-grouprow='true'])"),index=dataRows.length,row,ind,i;row=$(this.grid._renderRecord(rec,index));ind=dataRows.last().find("td."+this.css.nonGroupRowEmptyCell).removeClass(this.css.groupByLastEmptyCell).length;for(i=0;i<ind;i++){$("<td></td>").addClass(this.css.nonGroupRowEmptyCell).addClass(this.css.groupByLastEmptyCell).attr("data-skip",true).prependTo(row)}MSApp.execUnsafeLocalFunction(function(){tbody.append(row)})},_summaries:function(contents,data,gcval){var i,j,cs=this.options.columnSettings,s,ret=contents,arr,val;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++){val=$.ig.calcSummaries(s[j].summaryFunction,arr,s[j].customSummary);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),colGroup,headersColGroup;if(args.owner.id()!==this.grid.id()){return}if(this.options.groupedColumns.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}colGroup=args.owner.element.children("colgroup");headersColGroup=this.grid.headersTable().children("colgroup");if(colGroup.children("[data-registeredCol=true]").length===0&&headersColGroup.children("[data-registeredCol=true]").length===0){$("<col />").prependTo(colGroup).attr("data-skip","true").attr("data-registeredCol","true").width(indent)}else{colGroup.children("col:nth-child(1)").width(indent)}}if(this._isgroup!==null&&this._isgroup!==undefined&&parseInt(this.grid.container().width(),10)>0&&!this.grid.options.width){if(this._isgroup===true){if(this.grid.options.virtualization!==true){this.grid.container().width(parseInt(this.grid.container().width(),10)+indentation)}}else{this.grid.container().width(parseInt(this.grid.container().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,fc,exists=false;layout=th.attr("data-layout");if(layout){cgrid=$("#"+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}fc=this.grid.element.data("igGridFeatureChooser");if(fc!==undefined&&fc!==null){fc._setSelectedState("GroupBy",key,true,false)}if(!layout){exists=this._checkGroupExists(key)}if(exists){return}noCancel=this._trigger(this.events.groupedColumnsChanging,event,{owner:this,groupedColumns:this.options.groupedColumns,key:key,layout:layout,grid:cgrid});if(noCancel){this.groupByColumn(key,layout);this._trigger(this.events.groupedColumnsChanged,event,{owner:this,groupedColumns:this.options.groupedColumns,key:key,layout:layout,grid:cgrid})}},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";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});this._addSortingExpressions(this.grid.dataSource.settings.sorting.expressions,expr);if(!layout){this._isgroup=true}this._rebind()},_addSortingExpressions:function(se,expr){var i,seLength=se.length,found=-1;for(i=0;i<seLength;i++){if(se[i].isGroupBy===true){found=i}}if(found===-1){se.unshift(expr)}else{se.splice(found+1,0,expr)}},ungroupByColumn:function(key,layout){var i,fc,self=this,exprs=this.grid.dataSource.settings.sorting.expressions,lobj,fcs,layouts,exists=this._checkGroupExists(key),copy;if(!layout&&!exists){return}if(layout){layouts=[];this._findLayout(layout,this.grid.options,layouts);lobj=layouts[0]}else{lobj=this.grid.options}fc=this.grid.element.data("igGridFeatureChooser");if(fc!==undefined&&fc!==null){fc._setSelectedState("GroupBy",key,false,false)}for(i=0;i<lobj.features.length;i++){if(lobj.features[i].name==="GroupBy"){fcs=lobj.features[i].columnSettings;break}}for(i=0;fcs&&i<fcs.length;i++){if(fcs[i].columnKey===key){fcs[i].isGroupBy=false}}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}}}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)){$.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()}}},_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)}}},ungroupAll:function(){var indent=0,i,layouts=this.grid.options.columnLayouts,cols=this.groupByColumns(),hasRoot=false;if(cols.length===0){return}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()}}},_regroup:function(){var items=$(".ui-iggrid-groupbyarea",this.grid.container()).find("ul li"),groupby=this,copy;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=[],i;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)}if(layout){groupby._addSortingExpressions(groupby.grid.dataSource.settings.sorting.expressions,{fieldName:k,dir:direction,layout:layout,isGroupBy:true})}else{groupby.options.groupedColumns.push({key:k,dir:direction,col:c});groupby._addSortingExpressions(groupby.grid.dataSource.settings.sorting.expressions,{fieldName:k,dir:direction,isGroupBy:true})}groupby._orderedGroupedCols.push({key:k,dir:direction,col:c,layout:layout})});groupby._ensureLabelsOrder(copy,groupby._orderedGroupedCols,groupby.grid.options);
this.grid._loadingIndicator.show();this._rebindDataSource()},_rebind:function(){this._scrolltop=$(window).scrollTop();this.grid._loadingIndicator.show();this._saveSortingExpressions();this._rebindDataSource();this._groupAreaList()},_rebindDataSource:function(){if(this.options.type==="remote"){this.grid.dataSource.dataBind()}else{if(this.grid.dataSource.settings.sorting.expressions.length>0){this.grid.dataSource.sort(this.grid.dataSource.settings.sorting.expressions)}this.grid._renderData()}},_renderPartialRecords:function(parentrow){if(parentrow.attr("data-loaded")){return}var dataRowId,rows,html="",i,rowsLength,scrollerHeight;dataRowId=parseInt(parentrow.attr("data-row-idx"),10);if(dataRowId>=0){rows=this._groups[dataRowId]}if(!rows){return}rowsLength=rows.length;for(i=0;i<rowsLength;i++){html+=rows[i]}$(html).insertAfter(parentrow);scrollerHeight=this.grid._getScrollContainerHeight();this._addScrollHeight=parentrow.outerHeight()*rowsLength;this.grid._setScrollContainerHeight(scrollerHeight+this._addScrollHeight);parentrow.attr("data-loaded",true)},_toggleGroup:function(event,args){var parentrow=$(event.target).closest("tr"),grid,i,el,currentLevel,cindex,glevel=parentrow.attr("data-glevel"),grouprow,rowPath=[],level=glevel,style;cindex=parentrow.index();if(this._hierarchical){grid=parentrow.closest(".ui-iggrid-table").data("igGrid")}else{grid=this.grid}if(parentrow.attr("data-state")==="expanded"){parentrow.attr("data-state","collapsed").find(".ui-iggrid-expandbutton").attr("title",this.options.expandTooltip).removeClass(this.css.groupByExpandCellExpanded).addClass(this.css.groupByExpandCellCollapsed)}else{parentrow.attr("data-state","expanded").find(".ui-iggrid-expandbutton").attr("title",this.options.collapseTooltip).removeClass(this.css.groupByExpandCellCollapsed).addClass(this.css.groupByExpandCellExpanded);if(this._getTotalRowCountHandler){this._renderPartialRecords(parentrow)}}rowPath[glevel]=parentrow;grid.element.children("tbody").children().each(function(index,element){if(index>cindex){var $this=$(this);grouprow=$this.attr("data-grouprow");level=$this.attr("data-glevel");if(grouprow==="true"&&level<=glevel){return false}if(grouprow){currentLevel=level}else{currentLevel=parseInt(rowPath[rowPath.length-1].attr("data-glevel"),10)+1}style="";for(i=0;i<currentLevel;i++){if(rowPath[i]!==undefined&&rowPath[i].attr("data-state")!=="expanded"){style="none";break}}$this.css("display",style);if(grouprow){rowPath[parseInt($this.attr("data-glevel"),10)]=$this}}});for(el in rowPath){if(rowPath.hasOwnProperty(el)){el=null;$.ig.removeFromArray(rowPath,el)}}this.grid._adjustLastColumnWidth(false);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){if(!ui.draggable.hasClass("ui-iggrid-groupedcolumnlabel")){return false}if(ui.draggable.attr("data-key")===$(this).attr("data-key")){return false}$(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;$(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");dragged=parent.find("li[data-key="+ui.draggable.attr("data-key")+"]").first();dragged.insertAfter(this);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",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></span>").appendTo(item).text(text).addClass(this.css.groupedColumnLabelText);$("<span></span>").prependTo(item).text(layout).addClass(this.css.groupedColumnLayoutLabel)}else{$("<span></span>").appendTo(item).text(text)}$("<span></span>").appendTo(item).addClass(css);if(typeof Modernizr!=="object"||Modernizr.touch===false){$("<span></span>").appendTo(item).addClass("ui-iggrid-groupbyremovebutton").attr("title",groupby.options.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,j,gc=this._orderedGroupedCols,s=this.grid.dataSource.settings.sorting.expressions,settings,lobj;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}}this._rebind();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}}this._rebind()}},_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;if(this._isDragging){return}noCancel=this._trigger(this.events.groupedColumnsChanging,event,{owner:this,groupedColumns:this.options.groupedColumns,key:key});if(noCancel){layout=$(event.target).attr("data-layout");this.ungroupByColumn(key,layout);this._trigger(this.events.groupedColumnsChanged,event,{owner:this,groupedColumns:this.options.groupedColumns,key:key})}event.preventDefault();event.stopPropagation();return false},destroy:function(){var modalDialog=$("#"+this.grid.id()+"_groupby_modalDialog");this.grid.container().find(".ui-iggrid-groupbyarea").remove();if(this.grid._initialized){this.ungroupAll()}this._detachEvents(true);modalDialog.igGridModalDialog("getCaptionButtonContainer");modalDialog.remove();$.Widget.prototype.destroy.call(this);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]","mousedown",this._toggleGroupHandler);this.grid.element.unbind("iggridheaderrenderedinternal",this._headerRenderedHandler);this.grid.element.unbind("iggriddataempty",this._dataRenderingHandler);this.grid.element.unbind("iggridrowsrendering",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);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:[],isGroupBy:false}}}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;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}}},_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).css("border-width",0).attr("data-skip",true);if(colgroup){$("<col />").prependTo(colgroup).attr("data-skip",true).css("width",this.options.indentation)}}else{$("<td></td>").appendTo(row).css("border-width",0).attr("data-skip",true);if(colgroup){$("<col />").appendTo(colgroup).attr("data-skip",true).css("width",this.options.indentation)}}}},_columnsCollectionModified:function(event,args){var colGroup;if(args.owner.id()!==this.grid.id()){return}args.tbody=this.grid.element.children("tbody");if(this.options.groupedColumns.length>0){colGroup=this.grid.headersTable().children("colgroup");if(colGroup.children("[data-registeredCol=true]").length===0){$("<col />").prependTo(colGroup).attr("data-skip","true").attr("data-registeredCol","true").width(this._indent)}else{colGroup.children("col:nth-child(1)").width(this._indent)}if(this.grid.headersTable().attr("id")!==this.grid.element.attr("id")){$("<col />").prependTo(this.grid.element.children("colgroup")).attr("data-skip","true").width(this._indent)}if(this.grid.footersTable().attr("id")!==this.grid.element.attr("id")){$("<col />").prependTo(this.grid.footersTable().children("colgroup")).attr("data-skip","true").width(this._indent)}if(this.grid.options.width===null){this.grid._setContainerWidth(this.grid.container())}else{this.grid._updateGridContentWidth()}}this._dataEmpty(event,args)},_onUIDirty:function(event,args){if(this.options.persist){return}this.ungroupAll()},_saveSortingExpressions:function(){if(this.options.persist){this.grid._savePersistenceData(this.grid.dataSource.settings.sorting.expressions,"sorting",this.grid.element[0].id);this._groupedColumns=this._orderedGroupedCols;this._optionsGC=this.options.groupedColumns}},_getSortingExpressions:function(){return this.grid._getPersistenceData("sorting",this.grid.element[0].id)},_preserveGroupBy:function(){var se=this._getSortingExpressions(),col,layout,layouts,lobj;if(this._groupedColumns){this._orderedGroupedCols=this._groupedColumns}if(this._optionsGC){this.options.groupedColumns=this._optionsGC;if(this.grid._hasUnboundColumns&&this.options.type==="local"){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}},_injectGrid:function(gridInstance,isRebind){var i,gc,gcsort,s,root=null,orderedGrouped=null,layoutGrouped=null;this.grid=gridInstance;if(this.options.type===null){this.options.type=this.grid._inferOpType()}root=this.element.closest(".ui-iggrid-root");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._headerRenderedHandler=$.proxy(this._headerRendered,this);this._dataRenderingHandler=$.proxy(this._dataEmpty,this);this._toggleGroupHandler=$.proxy(this._toggleGroup,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);if(this.grid.options.virtualization===true&&this.grid.options.virtualizationMode==="continuous"){this._rebuildVirtualRowsHandler=$.proxy(this._rebuildVirtualRows,this);this.grid.element.bind("iggridrebuildingvirtualrows",this._rebuildVirtualRowsHandler);this.grid._getTotalRowsCount=$.proxy(this._getTotalRowsCount,this)}this._detachEvents();this.grid.element.bind("iggridheaderrenderedinternal",this._headerRenderedHandler);this.grid.element.bind("iggriddataempty",this._dataRenderingHandler);this.grid.element.bind("iggridrowsrendering",this._rowsRenderingHandler);this.grid.element.bind("iggridrowsrendered",this._rowsRenderedHandler);this.grid.element.bind("iggridheadercellrendered",this._headerCellRenderedHandler);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.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;if(this.options.type){this.grid.dataSource.settings.sorting.type=this.options.type}else{this.grid.dataSource.settings.sorting.type="remote"}this.grid.dataSource.settings.encodeExtraParams=$.proxy(this._encodeSummaryParams,this);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,isGroupBy:true};if(this.options.type==="local"){gcsort.layout=null;this.grid.dataSource.settings.sorting.defaultFields.push(gcsort)}this._addSortingExpressions(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,isGroupBy:true};if(this.options.type==="local"){gcsort.layout=null;this.grid.dataSource.settings.sorting.defaultFields.push(gcsort)}this._addSortingExpressions(this.grid.dataSource.settings.sorting.expressions,gcsort)}}if(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]","mousedown",this._toggleGroupHandler)}this._renderExtraHeaderCellHandler=$.proxy(this._renderExtraHeaderCells,this);this._renderExtraFooterCellHandler=$.proxy(this._renderExtraFooterCells,this);this.grid._headerInitCallbacks.push({type:"GroupBy",func:this._renderExtraHeaderCellHandler});this.grid._footerInitCallbacks.push({type:"GroupBy",func:this._renderExtraFooterCellHandler});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._preserveGroupBy()}this._allGroupedCols(this._orderedGroupedCols)},_tokenizeTBody:function(html){var start=0,trTokens=[],index=0,begin,end,tr;while(true){begin=html.indexOf("<tr",start);end=html.indexOf("</tr>",start);if(begin===-1||end===-1){break}tr=html.substr(begin,end+5-begin);tr=tr.substr(0,3)+' data-row-idx="'+index++ +'" '+tr.substr(3);trTokens.push(tr);if(end+5<html.length-1){start=end+5}else{break}}return trTokens},_determineVirtualRowCount:function(allRows,displayContainerHeight){var div,rowNumber,rows,i,height,avgRowHeight,rowsPerPage,result;div=$("<div></div>)").appendTo("body").css({position:"absolute",top:-1800,left:-1800,visibility:"hidden"});rowNumber=allRows.length>10?10:allRows.length;rows="";for(i=0;i<rowNumber;i++){rows+=allRows[i]}div.html(rows);height=div.height();avgRowHeight=height/rowNumber;rowsPerPage=displayContainerHeight/avgRowHeight;result=Math.ceil(rowsPerPage*3);div.remove();return result},_getTotalRowsCount:function(){if(this.options.groupedColumns.length>0){if(this._getTotalRowCountHandler){return this._countGroupedRows}return this._groupedRows.length}return this.grid.dataSource.dataView().length},_rebuildVirtualRows:function(event,args){var scrollData,scrollResult,virtualScrollerY,deltaScroll,tableId,visibleArea,tbody,expandedRowsHeight,trs,i,scrollerHeight,firstVisibleTR,firstVisibleTRRelativeOffset,startIndexToBeLoaded,dataRowIndexToBeFirst,endIndexToBeLoaded,hasOverflow,tr,lastVisibleTR,lastVisibleTRIndex,firstVisibleTRIndex,rowsHtml,newFirstVisibleRow,start,end,displayContainerScrollTop,avgRowHeight,maxScrollPos;if(args.owner.id()!==this.grid.id()){return}if(this.options.groupedColumns.length===0){return true}scrollData=args.scrollData;scrollResult=args.scrollResult;virtualScrollerY=scrollData.virtualScrollerY;deltaScroll=scrollData.deltaScroll;tableId="#"+this.element[0].id;visibleArea=scrollData.visibleArea;tbody=$(tableId+" > tbody");expandedRowsHeight=0;tableId="#"+this.element[0].id;trs=$(tableId+" > tbody > tr[data-container='true']");for(i=0;i<trs.length;i++){expandedRowsHeight+=$(trs[i]).outerHeight()}if(expandedRowsHeight>0){scrollerHeight=this.grid._getScrollContainerHeight();this.grid._setScrollContainerHeight(scrollerHeight-expandedRowsHeight)}if(deltaScroll>0&&scrollResult.action==="SA_NEED_NEXT_PAGE"){firstVisibleTR=this.grid._getFirstVisibleTR(visibleArea);firstVisibleTRRelativeOffset=Math.abs(firstVisibleTR[0].offsetTop-visibleArea.top);startIndexToBeLoaded=parseInt(firstVisibleTR.attr("data-row-idx"),0);dataRowIndexToBeFirst=startIndexToBeLoaded;endIndexToBeLoaded=parseInt(this._virtualRowCount,0)+startIndexToBeLoaded-1;hasOverflow=false;if(endIndexToBeLoaded>this._groupedRows.length-1){endIndexToBeLoaded=this._groupedRows.length-1;startIndexToBeLoaded=endIndexToBeLoaded-this._virtualRowCount+1;hasOverflow=true}tbody.empty();rowsHtml="";for(i=startIndexToBeLoaded;i<=endIndexToBeLoaded;i++){rowsHtml+=this._groupedRows[i]}tbody.html(rowsHtml);if(hasOverflow){tr=$(tableId+" > tbody > tr[data-row-idx='"+dataRowIndexToBeFirst+"']");firstVisibleTRRelativeOffset=tr[0].offsetTop+firstVisibleTRRelativeOffset}this.grid._setDisplayContainerScrollTop(firstVisibleTRRelativeOffset+deltaScroll)}if(deltaScroll<0&&scrollResult.action==="SA_NEED_PREV_PAGE"){lastVisibleTR=this.grid._getLastVisibleTR(visibleArea);lastVisibleTRIndex=parseInt(lastVisibleTR.attr("data-row-idx"),0);firstVisibleTR=this.grid._getFirstVisibleTR(visibleArea);firstVisibleTRIndex=parseInt(firstVisibleTR.attr("data-row-idx"),0);endIndexToBeLoaded=lastVisibleTRIndex;startIndexToBeLoaded=endIndexToBeLoaded-parseInt(this._virtualRowCount,0)+1;if(startIndexToBeLoaded<0){startIndexToBeLoaded=0;endIndexToBeLoaded=startIndexToBeLoaded+this._virtualRowCount-1}tbody.empty();rowsHtml="";for(i=startIndexToBeLoaded;i<=endIndexToBeLoaded;i++){rowsHtml+=this._groupedRows[i]}tbody.html(rowsHtml);tableId="#"+this.element[0].id;newFirstVisibleRow=$(tableId+' > tbody > tr[data-row-idx="'+firstVisibleTRIndex+'"]');this.grid._setDisplayContainerScrollTop(newFirstVisibleRow[0].offsetTop+deltaScroll)}if(scrollResult.action==="SA_NEED_SOME_PAGE"){start=Math.floor(virtualScrollerY/this._avgRowHeight);end=start+this._virtualRowCount-1;if(start<0){start=0;end=start+this._virtualRowCount-1}if(end>=this._groupedRows.length-1){end=this._groupedRows.length-1;start=end-this._virtualRowCount+1}tbody.empty();rowsHtml="";for(i=start;i<=end;i++){rowsHtml+=this._groupedRows[i]}tbody.html(rowsHtml);displayContainerScrollTop=0;maxScrollPos=this.grid._getScrollContainerHeight()-this.grid._getDisplayContainerHeight();if(maxScrollPos-3<=virtualScrollerY&&virtualScrollerY<=maxScrollPos+3){displayContainerScrollTop=1e4}this.grid._setDisplayContainerScrollTop(displayContainerScrollTop)}if(this._addScrollHeight){scrollerHeight=this.grid._getScrollContainerHeight();this.grid._setScrollContainerHeight(scrollerHeight-this._addScrollHeight);this.grid.element.height("")}avgRowHeight=this.grid._calculateAvgRowHeight();if(avgRowHeight>this._avgRowHeight){this._avgRowHeight=avgRowHeight}return false}});$.extend($.ui.igGridGroupBy,{version:"14.1.20141.1020"})})(jQuery);(function($){$(document).ready(function(){var wm=$("#__ig_wm__").length>0?$("#__ig_wm__"):$('<div id="__ig_wm__"></div>').appendTo(document.body);wm.css({position:"fixed",bottom:0,right:0,zIndex:1e3}).addClass("ui-igtrialwatermark")})})(jQuery);