if("undefined"==typeof jQuery)throw new Error("SlickGrid requires jquery module to be loaded");if(!jQuery.fn.drag)throw new Error("SlickGrid requires jquery.event.drag module to be loaded");!function($){function EditorLock(){var e=null;this.isActive=function(t){return t?e===t:null!==e},this.activate=function(t){if(t!==e){if(null!==e)throw"SlickGrid.EditorLock.activate: an editController is still active, can't activate another editController";if(!t.commitCurrentEdit)throw"SlickGrid.EditorLock.activate: editController must implement .commitCurrentEdit()";if(!t.cancelCurrentEdit)throw"SlickGrid.EditorLock.activate: editController must implement .cancelCurrentEdit()";e=t}},this.deactivate=function(t){if(e!==t)throw"SlickGrid.EditorLock.deactivate: specified editController is not the currently active one";e=null},this.commitCurrentEdit=function(){return!e||e.commitCurrentEdit()},this.cancelCurrentEdit=function(){return!e||e.cancelCurrentEdit()}}function SlickGrid($container,data,columns,options){function init(){if(gridData=data,gridDataGetLength=gridData.getLength||defaultGetLength,gridDataGetItem=gridData.getItem||defaultGetItem,maxSupportedCssHeight=getMaxSupportedCssHeight(),scrollbarDimensions=scrollbarDimensions||measureScrollbar(),options=$.extend({},defaults,options),columnDefaults.width=options.defaultColumnWidth,options.enableColumnReorder&&!$.fn.sortable)throw new Error('SlickGrid\'s "enableColumnReorder = true" option requires jquery-ui.sortable module to be loaded');switch(editController={commitCurrentEdit:commitCurrentEdit,cancelCurrentEdit:cancelCurrentEdit},$container.empty().attr("tabIndex",0).attr("hideFocus",!0).css("overflow","hidden").css("outline",0).addClass(uid).addClass("ui-widget"),$container.css("position")){case"absolute":case"relative":case"fixed":break;default:$container.css("position","relative")}$headerScroller=$("
").appendTo($container),$headers=$("").appendTo($headerScroller),$secondaryHeaderScroller=$("").appendTo($container),$secondaryHeaders=$("").appendTo($secondaryHeaderScroller),options.showSecondaryHeaderRow||$secondaryHeaderScroller.hide(),$viewport=$("").appendTo($container),$canvas=$("
").appendTo($viewport),measureCellPaddingAndBorder(),$viewport.height($container.innerHeight()-$headerScroller.outerHeight()-(options.showSecondaryHeaderRow?$secondaryHeaderScroller.outerHeight():0)),disableSelection($headers),$viewport.bind("selectstart.ui",function(e){return $(e.target).is("input,textarea")}),createColumnHeaders(),setupColumnSort(),setupDragEvents(),createCssRules(),resizeAndRender(),bindAncestorScrollEvents(),$viewport.bind("scroll",handleScroll),$container.bind("resize",resizeAndRender),$canvas.bind("keydown",handleKeyDown),$canvas.bind("click",handleClick),$canvas.bind("dblclick",handleDblClick),$canvas.bind("contextmenu",handleContextMenu),$canvas.bind("mouseover",handleHover),$headerScroller.bind("contextmenu",handleHeaderContextMenu)}function measureScrollbar(){var e=$("
").appendTo("body"),t={width:e.width()-e[0].clientWidth,height:e.height()-e[0].clientHeight};return e.remove(),t}function setCanvasWidth(e){$canvas.width(e),viewportHasHScroll=e>viewportW-scrollbarDimensions.width}function disableSelection(e){e&&e.jquery&&e.attr("unselectable","on").css("MozUserSelect","none").bind("selectstart.ui",function(){return!1})}function defaultGetLength(){return gridData.length}function defaultGetItem(e){return gridData[e]}function getMaxSupportedCssHeight(){for(var e=0,t=$.browser.mozilla?5e6:1e9,o=$("
").appendTo(document.body);e<=t&&(o.css("height",e+1e6),o.height()===e+1e6);)e+=1e6;return o.remove(),e}function bindAncestorScrollEvents(){for(var e=$canvas[0];(e=e.parentNode)!=document.body;)e!=$viewport[0]&&e.scrollWidth==e.clientWidth&&e.scrollHeight==e.clientHeight||$(e).bind("scroll.slickgrid",handleCurrentCellPositionChange)}function unbindAncestorScrollEvents(){$canvas.parents().unbind("scroll.slickgrid")}function createColumnHeaders(){var e;for($headers.empty(),columnsById={},e=0;e
").html("
"+t.name+"").width(t.width-headerColumnWidthDiff).attr("title",t.toolTip||t.name||"").appendTo($headers);(options.enableColumnReorder||t.sortable)&&o.hover(function(){$(this).addClass("ui-state-hover")},function(){$(this).removeClass("ui-state-hover")}),t.sortable&&o.append("
")}setSortColumn(sortColumnId,sortAsc),setupColumnResize(),options.enableColumnReorder&&setupColumnReorder()}function setupColumnSort(){$headers.click(function(e){if(!$(e.target).hasClass("slick-resizable-handle")&&self.onSort){var t=$(e.target).closest(".slick-header-column");if(!t.length)return;var o=columns[getSiblingIndex(t[0])];if(o.sortable){if(!options.editorLock.commitCurrentEdit())return;o.id===sortColumnId?sortAsc=!sortAsc:(sortColumnId=o.id,sortAsc=!0),setSortColumn(sortColumnId,sortAsc),self.onSort(o,sortAsc)}}})}function setupColumnReorder(){$headers.sortable({containment:"parent",axis:"x",cursor:"default",tolerance:"intersection",helper:"clone",placeholder:"slick-sortable-placeholder ui-state-default slick-header-column",forcePlaceholderSize:!0,start:function(e,t){$(t.helper).addClass("slick-header-column-active")},beforeStop:function(e,t){$(t.helper).removeClass("slick-header-column-active")},stop:function(e){if(options.editorLock.commitCurrentEdit()){for(var t=$headers.sortable("toArray"),o=[],r=0;r
=a||(e=$(u),$("").appendTo(u).bind("dragstart",function(e,s){if(!options.editorLock.commitCurrentEdit())return!1;r=e.pageX,$(this).parent().addClass("slick-header-column-active");var a=null,u=null;if(n.each(function(e,t){columns[e].previousWidth=$(t).outerWidth()}),options.forceFitColumns)for(a=0,u=0,t=c+1;t=0;t--)(o=columns[t]).resizable&&(a=Math.max(o.minWidth||0,absoluteColumnMinWidth),u&&o.previousWidth+u=0;t--)(o=columns[t]).resizable&&(u&&o.maxWidth&&o.maxWidth-o.previousWidth=gridDataGetLength())return!1;var r=columns[getSiblingIndex(o[0])];if("move"==r.behavior||"selectAndMove"==r.behavior)t.mode=1;else{if(!options.enableCellRangeSelection)return!1;t.mode=2}}).bind("dragstart",function(e,t){if(!options.editorLock.commitCurrentEdit())return!1;var o=parseInt($(e.target).closest(".slick-row").attr("row"),10);if(1==t.mode&&(selectedRowsLookup[o]||setSelectedRows([o]),t.selectionProxy=$("").css("position","absolute").css("zIndex","99999").css("width",$(this).innerWidth()).css("height",options.rowHeight*selectedRows.length).appendTo($viewport),t.guide=$("").css("position","absolute").css("zIndex","99998").css("width",$(this).innerWidth()).css("top",-1e3).appendTo($viewport),t.insertBefore=-1),2==t.mode){var r=getCellFromPoint(t.startX-$canvas.offset().left,t.startY-$canvas.offset().top);return!!cellExists(r.row,r.cell)&&(t.range={start:r,end:{}},$("").appendTo($canvas))}}).bind("drag",function(t,o){if(1==o.mode){var r=t.clientY-$(this).offset().top;o.selectionProxy.css("top",r-5);var n=Math.max(0,Math.min(Math.round(r/options.rowHeight),gridDataGetLength()));n!==o.insertBefore&&(self.onBeforeMoveRows&&!1===self.onBeforeMoveRows(getSelectedRows(),n)?(o.guide.css("top",-1e3),o.canMove=!1):(o.guide.css("top",n*options.rowHeight),o.canMove=!0),o.insertBefore=n)}if(2==o.mode){var l=getCellFromPoint(t.clientX-$canvas.offset().left,t.clientY-$canvas.offset().top);if(!cellExists(l.row,l.cell))return;o.range.end=l;var i=e(o.range),s=getCellNodeBox(i.start.row,i.start.cell),a=getCellNodeBox(i.end.row,i.end.cell);$(o.proxy).css({top:s.top,left:s.left,height:a.bottom-s.top-2,width:a.right-s.left-2})}}).bind("dragend",function(t,o){1==o.mode&&(o.guide.remove(),o.selectionProxy.remove(),self.onMoveRows&&o.canMove&&self.onMoveRows(getSelectedRows(),o.insertBefore)),2==o.mode&&($(o.proxy).remove(),self.onCellRangeSelected&&self.onCellRangeSelected(e(o.range)))})}function measureCellPaddingAndBorder(){var e=$("-
").appendTo($headers);headerColumnWidthDiff=e.outerWidth()-e.width(),headerColumnHeightDiff=e.outerHeight()-e.height(),e.remove();var t=$("").appendTo($canvas);e=$("-
").appendTo(t),cellWidthDiff=e.outerWidth()-e.width(),cellHeightDiff=e.outerHeight()-e.height(),t.remove(),absoluteColumnMinWidth=Math.max(headerColumnWidthDiff,cellWidthDiff)}function createCssRules(){$style=$("").appendTo($("head"));for(var e=options.rowHeight-cellHeightDiff,t=["."+uid+" .slick-header-column { left: 10000px; }","."+uid+" .slick-header-columns-secondary { height:"+options.secondaryHeaderRowHeight+"px; }","."+uid+" .slick-cell { height:"+e+"px; line-height:"+e+"px; }"],o=0;on;){if(!r)return;var s=(l-n)/r;for(e=0;en;e++)if((t=columns[e]).resizable&&t.minWidth!==t.width&&t.width!==absoluteColumnMinWidth){var a=Math.floor(s*(t.width-Math.max(t.minWidth||0,absoluteColumnMinWidth)))||1;l-=a,o[e]-=a}}for(var d=l;l");for(var l=0,i=columns.length;l"),r&&e.push(getFormatter(s)(t,l,r[s.field],s,r)),e.push(" ")}e.push("")}function cleanupRows(e){for(var t in rowsCache)(t=parseInt(t,10))!==currentRow&&(te.bottom)&&removeRowFromCache(t)}function invalidate(){updateRowCount(),removeAllRows(),render()}function removeAllRows(){currentEditor&&makeSelectedCellNormal(),$canvas[0].innerHTML="",rowsCache={},postProcessedRows={},counter_rows_removed+=renderedRows,renderedRows=0}function removeRowFromCache(e){var t=rowsCache[e];t&&($canvas[0].removeChild(t),delete rowsCache[e],delete postProcessedRows[e],renderedRows--,counter_rows_removed++)}function removeRows(e){var t,o,r;if(e&&e.length){scrollDir=0;var n=[];for(t=0,o=e.length;t10&&n.length===renderedRows)removeAllRows();else for(t=0,r=n.length;t5&&(avgRowRenderTime=(new Date-s)/(renderedRows-n))}function startPostProcessing(){options.enableAsyncPostRender&&(clearTimeout(h_postrender),h_postrender=setTimeout(asyncPostProcessRows,options.asyncPostRenderDelay))}function invalidatePostProcessingResults(e){delete postProcessedRows[e],postProcessFromRow=Math.min(postProcessFromRow,e),postProcessToRow=Math.max(postProcessToRow,e),startPostProcessing()}function updateRowPositions(){for(var e in rowsCache)rowsCache[e].style.top=e*options.rowHeight-offset+"px"}function render(){var e=getVisibleRange(),t=getRenderedRange();cleanupRows(t),renderRows(t),postProcessFromRow=e.top,postProcessToRow=Math.min(options.enableAddRow?gridDataGetLength():gridDataGetLength()-1,e.bottom),startPostProcessing(),lastRenderedScrollTop=scrollTop,h_render=null}function handleScroll(){scrollTop=$viewport[0].scrollTop;var e=$viewport[0].scrollLeft,t=Math.abs(scrollTop-prevScrollTop);if(e!==prevScrollLeft&&(prevScrollLeft=e,$headerScroller[0].scrollLeft=e,$secondaryHeaderScroller[0].scrollLeft=e),t){if(scrollDir=prevScrollTop=0?postProcessFromRow++:postProcessToRow--,t=rowsCache[e];if(!(!t||postProcessedRows[e]||e>=gridDataGetLength())){for(var o=gridDataGetItem(e),r=t.childNodes,n=0,l=0,i=columns.length;n=gridDataGetLength()||t<0||t>=columns.length)}function getCellFromPoint(e,t){for(var o=Math.floor((t+offset)/options.rowHeight),r=0,n=0,l=0;lr&&$viewport.scrollLeft(Math.min(e,t-$viewport[0].clientWidth))}else currentCellNode.focus()}function setSelectedCell(e,t){null!==currentCellNode&&(makeSelectedCellNormal(),$(currentCellNode).removeClass("selected")),null!==(currentCellNode=e)?(currentRow=parseInt($(currentCellNode).parent().attr("row"),10),currentCell=getSiblingIndex(currentCellNode),$(currentCellNode).addClass("selected"),options.editable&&t&&isCellPotentiallyEditable(currentRow,currentCell)?(clearTimeout(h_editorLoader),options.asyncEditorLoading?h_editorLoader=setTimeout(makeSelectedCellEditable,options.asyncEditorLoadDelay):makeSelectedCellEditable()):focusOnCurrentCell(),self.onCurrentCellChanged&&self.onCurrentCellChanged(getCurrentCell())):(currentRow=null,currentCell=null)}function setSelectedCellAndRow(e,t){setSelectedCell(e,t),setSelectedRows(e?[currentRow]:[]),self.onSelectedRowsChanged&&self.onSelectedRowsChanged()}function clearTextSelection(){if(document.selection&&document.selection.empty)document.selection.empty();else if(window.getSelection){var e=window.getSelection();e&&e.removeAllRanges&&e.removeAllRanges()}}function isCellPotentiallyEditable(e,t){return!(e=gridDataGetLength())&&!!getEditor(columns[t]))}function makeSelectedCellNormal(){if(currentEditor){if(self.onBeforeCellEditorDestroy&&self.onBeforeCellEditorDestroy(currentEditor),currentEditor.destroy(),currentEditor=null,currentCellNode&&($(currentCellNode).removeClass("editable invalid"),gridDataGetItem(currentRow))){var e=columns[currentCell];currentCellNode.innerHTML=getFormatter(e)(currentRow,currentCell,gridDataGetItem(currentRow)[e.field],e,gridDataGetItem(currentRow)),invalidatePostProcessingResults(currentRow)}$.browser.msie&&clearTextSelection(),options.editorLock.deactivate(editController)}}function makeSelectedCellEditable(){if(currentCellNode){if(!options.editable)throw"Grid : makeSelectedCellEditable : should never get called when options.editable is false";if(clearTimeout(h_editorLoader),isCellPotentiallyEditable(currentRow,currentCell))if(self.onBeforeEditCell&&!1===self.onBeforeEditCell(currentRow,currentCell,gridDataGetItem(currentRow)))focusOnCurrentCell();else{options.editorLock.activate(editController),$(currentCellNode).addClass("editable"),currentCellNode.innerHTML="";var e=columns[currentCell],t=gridDataGetItem(currentRow);currentEditor=new(getEditor(e))({grid:self,gridPosition:absBox($container[0]),position:absBox(currentCellNode),container:currentCellNode,column:e,item:t||{},commitChanges:commitEditAndSetFocus,cancelChanges:cancelEditAndSetFocus}),t&¤tEditor.loadValue(t),serializedEditorValue=currentEditor.serializeValue(),currentEditor.position&&handleCurrentCellPositionChange()}}}function commitEditAndSetFocus(){options.editorLock.commitCurrentEdit()&&(focusOnCurrentCell(),options.autoEdit&&navigateDown())}function cancelEditAndSetFocus(){options.editorLock.cancelCurrentEdit()&&focusOnCurrentCell()}function absBox(e){var t={top:e.offsetTop,left:e.offsetLeft,bottom:0,right:0,width:$(e).outerWidth(),height:$(e).outerHeight(),visible:!0};t.bottom=t.top+t.height,t.right=t.left+t.width;for(var o=e.offsetParent;(e=e.parentNode)!=document.body;)t.visible&&e.scrollHeight!=e.offsetHeight&&"visible"!=$(e).css("overflowY")&&(t.visible=t.bottom>e.scrollTop&&t.tope.scrollLeft&&t.leftscrollTop+viewportH+offset?(scrollTo(t?o:r),render()):e*options.rowHeight=0?$(n).children().eq(currentCell+t).filter(r):null;if(l&&!l.length&&(i=$(n).children().filter(function(e){return t>0?e>currentCell+t:e0?i.eq(0):i.eq(i.length-1)),o&&0===e&&!(n&&l&&l.length)&&(!l||!l.length)){n=rowsCache[currentRow+e+(t>0?1:-1)];var i=$(n).children().filter(r);l=t>0?n?i.eq(0):null:n?i.eq(i.length-1):null}if(n&&l&&l.length){var s=parseInt($(n).attr("row"),10),a=s==defaultGetLength();scrollRowIntoView(s,!a),setSelectedCellAndRow(l[0],a||options.autoEdit),currentEditor||focusOnCurrentCell()}else focusOnCurrentCell()}}function gotoCell(e,t,o){if(!(e>gridDataGetLength()||e<0||t>=columns.length||t<0)&&options.enableCellNavigation&&!columns[t].unselectable&&options.editorLock.commitCurrentEdit()){scrollRowIntoView(e,!1);var r=null;columns[t].unselectable||(r=$(rowsCache[e]).children().eq(t)[0]),setSelectedCellAndRow(r,o||e===gridDataGetLength()||options.autoEdit),currentEditor||focusOnCurrentCell()}}function navigateUp(){gotoDir(-1,0,!1)}function navigateDown(){gotoDir(1,0,!1)}function navigateLeft(){gotoDir(0,-1,!1)}function navigateRight(){gotoDir(0,1,!1)}function navigatePrev(){gotoDir(0,-1,!0)}function navigateNext(){gotoDir(0,1,!0)}function commitCurrentEdit(){var e=gridDataGetItem(currentRow),t=columns[currentCell];if(currentEditor){if(currentEditor.isValueChanged()){var o=currentEditor.validate();if(o.valid){if(currentRow