<script>
var lastcol;
var lastrow;
var isanyddvisible = false;
var lastTopPos;
var lastLeftPos;
var DDCELLCLICKED = false;
////-------------------------------------------------------////
var objAC = new AW.UI.Grid;
objAC.setCellData(function(col, row){return col + "." + row });
objAC.setHeaderText("header");
objAC.setStyle("width", '130');
objAC.setStyle("height", '100%');
objAC.setVirtualMode(false);
objAC.setCellEditable(false);
objAC.getRowsTemplate().setStyle('background', 'lightyellow');
objAC.setColumnCount(1);
objAC.setRowCount(140);
////-------------------------------------------------------////
objAC.onCellClicked = function(event, column, row){
DDCELLCLICKED = true;
obj.onCellClicked();
obj.setCellText(this.getCellText(column,row), lastcol,lastrow);
obj.getCellTemplate(lastcol,lastrow).refresh();
}
////-------------------------------------------------------////
var objtextarea = new AW.HTML.DIV;
objtextarea.setStyle("height", "180");
objtextarea.setStyle("POSITION", "ABSOLUTE");
objtextarea.setStyle("Z-INDEX", "1000000000");
objtextarea.setStyle("display", "none") ;
objtextarea.setContent("text", objAC.toString());
document.write(objtextarea);
////-------------------------------------------------------////
var obj = new AW.UI.Grid;
obj.setCellData(function(col, row){return col + "." + row});
obj.setHeaderText("header");
obj.setVirtualMode(false);
obj.setCellEditable(true);
obj.setColumnCount(6);
obj.setRowCount(10);
////-------------------------------------------------------////
/////// SCROLL-TOP CHANGED (ENABLE / DISABLE VERT.-SCROLL )//////////////
obj.onScrollTopChanged = function(top){
if(isanyddvisible){ if (top != lastTopPos){ return "obj.setScrollTop(lastTopPos)" } }
}
obj.onScrollTopError = function(error){ eval(error); }
////-------------------------------------------------------////
/////// SCROLL-LEFT CHANGED (ENABLE / DISABLE HORIZ.-SCROLL )///////
obj.onScrollLeftChanged = function(left){
if(isanyddvisible){ if (left != lastLeftPos){ return "obj.setScrollLeft(lastLeftPos)" } }
}
obj.onScrollLeftError = function(error){ eval(error); }
////-------------------------------------------------------////
obj.onCellClicked = function(event, column, row){
if( isanyddvisible ) {
objtextarea.setStyle("display", "none") ; /// hide drop-down object
isanyddvisible = false;
obj.setScrollTop( lastTopPos );
obj.setScrollLeft( lastLeftPos );
}
}
////-------------------------------------------------------////
obj.onCellTextChanged = function(event, column, row){
if( !DDCELLCLICKED ) {
SearchFunction( column,row);
objAC.getRowsTemplate().refresh();
}
}
////-------------------------------------------------------////
obj.onCellEditStarted = function(event, column, row){
/// retaint scroll pos
lastTopPos = obj.getScrollTop();
lastLeftPos = obj.getScrollLeft();
isanyddvisible = true;
/// postion the drop-down object below cell
var el = obj.getCellTemplate(column, row).element();
if(!AW.ie) {
objtextarea.setStyle("left", AW.getLeft(el) - obj.getScrollLeft() );
objtextarea.setStyle("top", AW.getTop(el) - obj.getScrollTop() + el.offsetHeight );
}
else{
objtextarea.setStyle("left", AW.getLeft(el) - 2 );
objtextarea.setStyle("top", AW.getTop(el) - 3 + el.offsetHeight );
}
objtextarea.setStyle("display", "block") ;
objAC.raiseEvent("adjustScrollHeight"); /////////// PATCH //////
objAC.refresh(); /////// PATCH ///////
lastcol=column;
lastrow=row;
SearchFunction( lastcol,lastrow);
}
////-------------------------------------------------------////
function SearchFunction(col,row){
objAC.setRowCount( 0 ) ;
objtextarea.setStyle("height", "29");
objAC.setHeaderText('Loading...' ,0);
objAC.refresh();
var tosearch = obj.getCellText(col, row).toUpperCase();
var rows = [], max = 140;
if(tosearch.length < 3){
objAC.setHeaderText('3 chars min' ,0);
objAC.refresh();
}
else{
if(tosearch != '' ){
for (var i=0; i<max; i++){
var cellval = objAC.getCellText(0, i);
if ( cellval.toUpperCase().substr(0, tosearch.length) == tosearch.substr(0, tosearch.length) ) {
rows.push(i);
}
}
}
setTimeout( function(){ ////*********/// SET TIMEOUT
rows.length > 0 ? objAC.setRowCount( rows.length ) : objAC.setRowCount(0 ) ;
if(rows.length == 0){
objtextarea.setStyle("height", "29");
objAC.setHeaderText('No Matches',0);
}
else{
objtextarea.setStyle("height", "180");
objAC.setHeaderText('Found::'+rows.length ,0);
}
objAC.setRowIndices(rows);
objAC.setScrollTop(0);
},100); ////*********//// END TIMEOUT
}
}
////-------------------------------------------------------////
document.write(obj);
</script>
var zz = -1;
var defaultEventHandler = obj.getEvent("onkeydown");
obj.setEvent("onkeydown", function(e){
if( isanyddvisible ) {
var ind = objAC.getRowIndices();
if(e.keyCode==40){
if(zz < objAC.getRowIndices().length - 1) zz++;
var ind2 = ind[zz];
objAC.setCurrentRow([ind2] );
objAC.setSelectedRows( [ind2] );
e.returnValue = false;
}
if(e.keyCode==38){
if(zz > 0) zz--;
var ind2 = ind[zz];
objAC.setCurrentRow([ind2] );
objAC.setSelectedRows([ind2] );
e.returnValue = false;
}
if(e.keyCode==35){ //// End Key
ACIITEMSELECTED = true;
objtextarea.setStyle("display", "none") ; /// hide drop-down object
obj.setScrollTop( lastTopPos );
obj.setScrollLeft( lastLeftPos );
isanyddvisible = false;
obj.onCellTextChanged = function(){}
obj.setCellText(objAC.getCellText(0,objAC.getSelectedRows( [ind2] ) ),lastcol,lastrow );
obj.getCellTemplate(lastcol,lastrow).refresh();
e.returnValue = false;
}
}
else{
defaultEventHandler.call(this, e);
e.returnValue = false;
}
} );
This topic is archived.