⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 igf_grid_editing.js

📁 一个JSF的商业组件的DEMO,infragistics-netadvantage.lic:NetAdvantage for JSF Vol1 2008,m21A99D6A11FF-9B33DC4B8
💻 JS
📖 第 1 页 / 共 2 页
字号:
// (c) 2007 Infragistics - Do NOT modify the content of this file
// Version 8.1.20081.1004

$IG.GridEditing=function(obj,objProps,control,parentCollection)
{$IG.GridEditing.initializeBase(this,[obj,objProps,control,parentCollection]);this._parentCollection=parentCollection;this._createObjects(objProps[0]);this._intializeComplete();this._grid=obj;this._gridElement=obj.elm.firstChild;this._container=obj.getGrid().elm;this._editCellCssClass="igGridCellEdit";this._containerMouseDownHandler=Function.createDelegate(this,this._onMousedownHandler);this._containerDoubleClickHandler=Function.createDelegate(this,this._onDblclickHandler);this._gridElementKeyDownHandler=Function.createDelegate(this,this._onKeydownHandler);this._gridElementKeyPress=Function.createDelegate(this,this._onKeypressHandler);this._gridElementBeforeSubmitHandler=Function.createDelegate(this,this._onBeforeSubmitHandler);this._parentCollection._addElementEventHandler(this._container,"click",this._containerMouseDownHandler);this._parentCollection._addElementEventHandler(this._container,"dblclick",this._containerDoubleClickHandler);this._parentCollection._addElementEventHandler(obj.elm,"keydown",this._gridElementKeyDownHandler);this._parentCollection._addElementEventHandler(obj.elm,"keypress",this._gridElementKeyPress)
this._parentCollection._addElementEventHandler(obj.elm,"beforesubmit",this._gridElementBeforeSubmitHandler)
this._parentCollection._addElementEventHandler(obj.elm,"submit",this._gridElementBeforeSubmitHandler)
this._cellInEditMode=null;this._currentEditor=null;this._lastEditedRow=-1;this.editors=new Object();}
$IG.GridEditing.prototype={get_editModeActions:function()
{return this._editModeActions;},destroy:function(){this.resetEditors();this._parentCollection._removeElementEventHandler(this._container,"click",this._containerMouseDownHandler);this._parentCollection._removeElementEventHandler(this._container,"dblclick",this._containerDoubleClickHandler);this._parentCollection._removeElementEventHandler(this._grid.elm,"keydown",this._gridElementKeyDownHandler);this._parentCollection._removeElementEventHandler(this._grid.elm,"keypress",this._gridElementKeyPress)
this._parentCollection._removeElementEventHandler(this._grid.elm,"beforesubmit",this._gridElementBeforeSubmitHandler)
this._parentCollection._removeElementEventHandler(this._grid.elm,"submit",this._gridElementBeforeSubmitHandler)},enterEditMode:function(cell)
{if(cell==null)
return;if(!this._activation&&this._lastEditedRow>=0&&this._lastEditedRow!=cell.getRowIndex()){this.exitEditMode();this._grid.onRowChange();}
if(this._cellInEditMode!=null){if(this._cellInEditMode.elm==cell.elm)
return;if(this._grid.getEditMode()=="row"){this.exitEditMode(true);}else{this.exitEditMode();}}
if(this._cellInEditMode!=null)
return;if(this._grid.getEditMode()=="row"&&this._lastEditedRow!=cell.getRowIndex()){this.__hideEditors(cell,null);}
var editor=this.__resolveEditor(cell);if(editor==null)
return;if(this.enteringEditMode)
return;this.enteringEditMode=true;var args=this.__raiseClientEvent("EnteringEditMode",$IG.CancelEditModeEventArgs,cell);if(args==null||!args.get_cancel())
{this.__showEditors(cell,editor);editor.enableEditor();this._cellInEditMode=cell;this._currentEditor=editor;this._lastEditedRow=cell.getRowIndex();this.enteringEditMode=false;this.__raiseClientEvent("EnteredEditMode",$IG.EditModeEventArgs,cell);}else{this.enteringEditMode=false;}},exitEditMode:function(doNotHideEditor)
{if(this._cellInEditMode!=null)
{var args=this.__raiseClientEvent("ExitingEditMode",$IG.CancelEditModeEventArgs,this._cellInEditMode);if(args==null||!args.get_cancel())
{var editor=this._currentEditor;this._container.style.position="";var val=editor.get_value();if(!doNotHideEditor){this.__hideEditors(this._cellInEditMode,editor);}
if(this._grid.getEditMode()!="row"){this._cellInEditMode.set_value(val,editor.get_displayText(val));}
this.__raiseClientEvent("ExitedEditMode",$IG.EditModeEventArgs,this._cellInEditMode);this._cellInEditMode=null;this._currentEditor=null;}}else{if(this._grid.getEditMode()=="row"){this.__hideEditors(null,null);}}},get_isInEditMode:function(cell)
{return(this._cellInEditMode==cell);},resetEditors:function()
{this.hideEditors();for(var i in this.editors){var editor=this.editors[i];if($IG.GridInternalWrapperEditor.isInstanceOfType(editor)){var columnEditor=document.getElementById(this._grid.getId()+":"+i);if(columnEditor!=null){if(columnEditor.firstChild==null)
columnEditor.appendChild(editor.elm);}}}
this.editors=new Object();this._lastEditedRow=-1;},hideEditors:function()
{this.exitEditMode();if(this._grid.getEditMode()=="row"){this.__hideEditors(null,null);;}},_onMousedownHandler:function(evnt)
{if(this._currentEditor!=null&&evnt.target==this._currentEditor._element)
return;if(this._editModeActions.get_mouseClick()==$IG.EditMouseClickAction.Single)
this.__enterEditModeEvntHandler(evnt);},_onDblclickHandler:function(evnt)
{if(this._currentEditor!=null&&evnt.target==this._currentEditor._element)
return;if(this._editModeActions.get_mouseClick()==$IG.EditMouseClickAction.Double)
this.__enterEditModeEvntHandler(evnt);},_onKeypressHandler:function(evnt)
{var key=evnt.keyCode;if(this._editModeActions.get_enableOnKeyPress())
{if(this._activation&&this._cellInEditMode==null)
{if(key==evnt.KEY_ESCAPE||key==evnt.KEY_RIGHT||key==evnt.KEY_TAB||key==evnt.KEY_LEFT||key==evnt.KEY_UP||key==evnt.KEY_DOWN)
return;var activeCell=this._activation.get_activeCell();if(activeCell!=null)
{this.enterEditMode(activeCell);if(this._cellInEditMode!=null&&this._currentEditor!=null){if(key!=evnt.KEY_RETURN){this._currentEditor.set_value(String.fromCharCode(key));this._currentEditor.__setCursorPosition(1);}
evnt.preventDefault();}}}}},_onKeydownHandler:function(evnt)
{var key=evnt.keyCode;if(key==evnt.KEY_ESCAPE){this.__editorLostFocus(evnt);}
if(this._activation)
{if(key==113)
{if(this._editModeActions.get_enableF2())
{var activeCell=this._activation.get_activeCell();if(activeCell!=null)
this.enterEditMode(activeCell);}}}},_activeCellChanging:function(event)
{var activeCell=event.getCurrentActiveCell();var newActiveCell=event.getNewActiveCell();if(newActiveCell==null||activeCell!=null&&activeCell.getRowIndex()!=newActiveCell.getRowIndex()){this.exitEditMode();activeCell.getGrid().onRowChange();this._lastEditedRow=-1;}},_activeCellChanged:function(cell)
{if(this._editModeActions.get_enableOnActive()){this.enterEditMode(cell);}},_onBeforeSubmitHandler:function(evt)
{ig.grid.inSubmit=true;this.resetEditors();ig.grid.inSubmit=false;},__showEditors:function(cell,editor){if(this._grid.getEditMode()=="row"){if(this._lastEditedRow!=cell.getRowIndex()){var colCount=this._grid.getColCount();var colIndex=cell.getIndex();var rowIndex=cell.getRowIndex();var position=new IgGridPosition(rowIndex,0);for(;position.col<colCount;position.col++){if(position.col!=colIndex){var aCell=this._grid.get_cellFromPosition(position);var aEditor=this.__resolveEditor(aCell);if(aEditor!=null){this.__showEditorForCell(aCell,aEditor);aEditor.saveState();}}}
this.__showEditorForCell(cell,editor);editor.saveState();}}else{this.__showEditorForCell(cell,editor);editor.saveState();}},__hideEditors:function(cell,editor){if(this._grid.getEditMode()=="row"){if(this._lastEditedRow<0)
return;var colCount=this._grid.getColCount();var position=new IgGridPosition(this._lastEditedRow,0);for(;position.col<colCount;position.col++){{var aCell=this._grid.get_cellFromPosition(position);var aEditor=this.__resolveEditor(aCell);if(aEditor!=null){var val=aEditor.get_value();var displayText=aEditor.get_displayText(val);this.__hideEditorForCell(aCell,aEditor);aCell.set_value(val,displayText);}}}
this._lastEditedRow=-1;}else{this.__hideEditorForCell(cell,editor);}},__restoreState:function(){if(this._grid.getEditMode()=="row"){if(this._lastEditedRow<0)
return;var colCount=this._grid.getColCount();var position=new IgGridPosition(this._lastEditedRow,0);for(;position.col<colCount;position.col++){var aCell=this._grid.get_cellFromPosition(position);var aEditor=this.__resolveEditor(aCell);if(aEditor!=null){aEditor.restoreState();}}}else{if(this._currentEditor!=null){this._currentEditor.restoreState();}}},__showEditorForCell:function(cell,editor){var cellValue=cell.get_value();cell.elm.setAttribute("val",cellValue);editor.cellHeight=cell.elm.offsetHeight;editor.cellWidth=cell.elm.offsetWidth
var leftCellBorder=cell.getBorder("left");var rightCellBorder=cell.getBorder("right");if(leftCellBorder>rightCellBorder){editor.cellWidth=editor.cellWidth-leftCellBorder;}else{editor.cellWidth=editor.cellWidth-rightCellBorder;}
var topCellBorder=cell.getBorder("top");var bottomCellBorder=cell.getBorder("bottom");if(topCellBorder>bottomCellBorder){editor.cellHeight=editor.cellHeight-topCellBorder;}else{editor.cellHeight=editor.cellHeight-bottomCellBorder;}
var isFirstRow=cell.elm.offsetParent.rows[0]==cell.elm.parentNode;var isLastRow=cell.elm.offsetParent.rows[cell.elm.offsetParent.rows.length-1]==cell.elm.parentNode;if(ig.isIE){if(cell.elm.previousSibling==null&&cell.elm.offsetParent!=null){var table=new IgUIElement(cell.elm.offsetParent);var leftBorder=table.getBorder("left");if(leftCellBorder<rightCellBorder){editor.cellWidth=editor.cellWidth+rightCellBorder/2;}else{editor.cellWidth=editor.cellWidth+leftCellBorder/2;}
if(leftBorder==0){editor.cellWidth=editor.cellWidth-leftCellBorder;}}
if(cell.elm.nextSibling==null&&cell.elm.offsetParent!=null){var table=new IgUIElement(cell.elm.offsetParent);var rightBorder=table.getBorder("right");if(leftCellBorder<rightCellBorder){editor.cellWidth=editor.cellWidth+rightCellBorder/2;}else{editor.cellWidth=editor.cellWidth+leftCellBorder/2;}
if(rightBorder==0){editor.cellWidth=editor.cellWidth-rightCellBorder;}}
if(cell.elm.offsetParent!=null&&(isFirstRow||cell.elm.parentNode.previousSibling==null)){var table=new IgUIElement(cell.elm.offsetParent);var topBorder=table.getBorder("top");if(!isFirstRow){topBorder=0;}
if(topCellBorder<bottomCellBorder){editor.cellHeight=editor.cellHeight+bottomCellBorder/2;}else{editor.cellHeight=editor.cellHeight+topCellBorder/2;}
if(topBorder==0){if(isFirstRow){editor.cellHeight=editor.cellHeight-topCellBorder;}else{editor.cellHeight=editor.cellHeight-topCellBorder/2;}}}
if(cell.elm.offsetParent!=null&&(isLastRow||cell.elm.parentNode.nextSibling==null)){var table=new IgUIElement(cell.elm.offsetParent);var bottomBorder=table.getBorder("bottom");if(!isLastRow){bottomBorder=0;}
if(topCellBorder<bottomCellBorder){editor.cellHeight=editor.cellHeight+bottomCellBorder/2;}else{editor.cellHeight=editor.cellHeight+topCellBorder/2;}
if(bottomBorder==0){if(isLastRow){editor.cellHeight=editor.cellHeight-bottomCellBorder;}else{editor.cellHeight=editor.cellHeight-bottomCellBorder/2;}}}}
else
if(ig.isFirefox){if(cell.elm.previousSibling==null&&cell.elm.offsetParent!=null){var table=new IgUIElement(cell.elm.offsetParent);var leftBorder=table.getBorder("left");if(leftCellBorder<rightCellBorder){if(leftBorder>leftCellBorder){editor.cellWidth=editor.cellWidth+Math.floor(rightCellBorder/2)-Math.floor(leftBorder/2);}else{editor.cellWidth=editor.cellWidth+Math.floor(rightCellBorder/2)-Math.floor(leftCellBorder/2);}}else{if(leftBorder>leftCellBorder){editor.cellWidth=editor.cellWidth+Math.floor(leftCellBorder/2)-Math.floor(leftBorder/2);}}}
if(cell.elm.nextSibling==null&&cell.elm.offsetParent!=null){var table=new IgUIElement(cell.elm.offsetParent);var rightBorder=table.getBorder("right");if(leftCellBorder<rightCellBorder){if(rightBorder>rightCellBorder){editor.cellWidth=editor.cellWidth+Math.floor(rightCellBorder/2)-Math.floor((rightBorder+1)/2);}}else{if(rightBorder>rightCellBorder){editor.cellWidth=editor.cellWidth+Math.floor(leftCellBorder/2)-Math.floor((rightBorder+1)/2);}else{editor.cellWidth=editor.cellWidth+Math.floor(leftCellBorder/2)-Math.floor((rightCellBorder+1)/2);}}}
if(cell.elm.offsetParent!=null&&(isFirstRow||cell.elm.parentNode.previousSibling==null)){var table=new IgUIElement(cell.elm.offsetParent);var topBorder=table.getBorder("top");if(topCellBorder<bottomCellBorder){if(topBorder>topCellBorder){if(isFirstRow)
editor.cellHeight=editor.cellHeight+Math.floor(bottomCellBorder/2)-Math.floor(topBorder/2);else{editor.cellHeight=editor.cellHeight+Math.floor(bottomCellBorder/2)-Math.floor(topCellBorder/2);}}else{editor.cellHeight=editor.cellHeight+Math.floor(bottomCellBorder/2)-Math.floor(topCellBorder/2);}}else{if(topBorder>topCellBorder){if(isFirstRow){editor.cellHeight=editor.cellHeight+Math.floor(topCellBorder/2)-Math.floor(topBorder/2);}}}}
if(cell.elm.offsetParent!=null&&(isLastRow||cell.elm.parentNode.nextSibling==null)){var table=new IgUIElement(cell.elm.offsetParent);var bottomBorder=table.getBorder("bottom");if(topCellBorder<bottomCellBorder){if(bottomBorder>bottomCellBorder){if(isLastRow){editor.cellHeight=editor.cellHeight+Math.floor(bottomCellBorder/2)-Math.floor(bottomBorder/2);}}}else{if(bottomBorder>bottomCellBorder){if(isLastRow)
editor.cellHeight=editor.cellHeight+Math.floor(topCellBorder/2)-Math.floor(bottomBorder/2);else{editor.cellHeight=editor.cellHeight+Math.floor(topCellBorder/2)-Math.floor(bottomCellBorder/2);}}else{editor.cellHeight=editor.cellHeight+Math.floor(topCellBorder/2)-Math.floor(bottomCellBorder/2);}}}}
if(editor.cellInnerHTML==null){editor.cellInnerHTML=cell.elm.innerHTML;editor.cellPadding=cell.getStyle("padding");cell.elm.innerHTML="";cell.setStyle("padding","0px");}
if(cell.elm.firstChild!=null)
cell.elm.insertBefore(editor.elm,cell.elm.firstChild);else
cell.elm.appendChild(editor.elm);editor.set_value(cellValue);editor.showEditor(0,0,editor.cellWidth,editor.cellHeight,this._editCellCssClass,cell.elm);},__hideEditorForCell:function(cell,editor){editor.hideEditor();cell.elm.innerHTML=editor.cellInnerHTML;cell.setStyle("padding",editor.cellPadding);cell.setSize(editor.cellWidth,editor.cellHeight);editor.cellInnerHTML=null;},__enterEditModeEvntHandler:function(evnt)
{if(evnt.event.button==0)
{var cell=ig.grid.getTargetCell(evnt.target);if(cell!=null)
this.enterEditMode(cell);}},__editorFocus:function(evnt)
{if(this._grid.getEditMode()!="row")
return;if(this._currentEditor!=null)
{this._currentEditor._originalNotifyFocus(evnt);}
this.enterEditMode(ig.grid.getTargetCell(evnt.target));},__editorLostFocus:function(evnt)
{if(this._currentEditor!=null)
{this._currentEditor._originalNotifyLostFocus(evnt);if(evnt!=null&&(evnt.type=="keydown"||evnt.type=="keypress"))
{var key=evnt.keyCode;if(key==evnt.KEY_TAB||key==evnt.KEY_RETURN)
{var cell=this._cellInEditMode;var nextCell=cell;do{if(!evnt.isShiftKeyPressed()){nextCell=this._grid.getNextCell(nextCell);}else
nextCell=this._grid.getPrevCell(nextCell);editor=this.__resolveEditor(nextCell);}while(editor==null&&nextCell!=null);if(this._grid.getEditMode()=="row"&&nextCell!=null&&cell!=null&&nextCell.getRowIndex()==cell.getRowIndex()){if(key==evnt.KEY_RETURN)
{evnt.stopPropagation();evnt.preventDefault();if(!this._activation){this.exitEditMode();this._grid.onRowChange(evnt);}}
return;}else{if(!this._activation){this._grid.onRowChange(evnt);}
this.exitEditMode();}
if(nextCell!=null)
{if(this._activation)
this._activation.set_activeCell(nextCell,true);evnt.stopPropagation();evnt.preventDefault();this._lastEditedRow=-1;}}
else
{if(key==evnt.KEY_ESCAPE){this.__restoreState();this.exitEditMode();}else if(key==evnt.KEY_RETURN)
{this.exitEditMode();evnt.stopPropagation();evnt.preventDefault();}
if(this._activation)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -