How to move up & down in datatable?

Hi,All

I want to move focus by direction key in datatable,now,left & right be ok,up or down be not,code as folloing:

<ui:table augmentTitle="false" binding="#{inputData.table1}" id="table1"

style="left: 195px; top: 155px; position: absolute; width: 805px" width="811">

<script><![CDATA[

............

/* key event */

function document.onkeydown()

{

switch(event.keyCode)

{

case 39:

case 40:

GoOtherText(1);

break;

case 37:

case 38:

GoOtherText(-1);

break;

default:

break;

}

}

function GoOtherText(iDirection)

{

var i= event.srcElement.sourceIndex;

var obj = document.all[i+iDirection];

while(i>=0 && obj.tagName.toUpperCase() !="INPUT")

{

obj = document.all[i+iDirection];

i+= iDirection;

if(i==-1||i>=document.all.length)return;

}

window.status = i;

if(obj.tagName.toUpperCase() =="INPUT" && obj.type=="text" )

{

obj.focus();

obj.select();

}

}

]]></script>

<ui:tableRowGroup binding="#{inputData.tableRowGroup1}" id="tableRowGroup1" rows="10"

sourceData="#{inputData.khdfSessionGetAmmeterByBooknumForInputData1}" sourceVar="currentRow">

<ui:tableColumn align="center" binding="#{inputData.tableColumn13}" headerText="nowdata" id="tableColumn13"

onKeyDown="document.onkeydown()" width="88">

<ui:textField binding="#{inputData.copydataText}" converter="#{inputData.bigDecimalConverter1}" id="copydataText"

onChange="" onMouseOut="" readOnly="#{inputData.khdfSessionGetAmmeterByBooknumForInputData1.value['jfbz']}"

style="text-align: right; width: 69px" text="#{currentRow.value['copydata']}"/>

</ui:tableColumn>

</ui:tableRowGroup>

</ui:table>

[3342 byte] By [nsqsmilea] at [2007-11-27 2:35:07]
# 1

Hi

I has resolved this problem.but moving left or right, obj.select() no play.

/* key event */

function document.onkeydown(sender)

{

switch(event.keyCode)

{

case 37: //left

GoH(-1);

break;

case 38: //up

GoV(-1);

break;

case 39: //right

GoH(1);

break;

case 40: //down

GoV(1);

break;

default:

break;

}

}

function GoH(iDirection)

{

var i= event.srcElement.sourceIndex;

var obj = document.all[i+iDirection];

while(i>=0 && obj.tagName.toUpperCase() !="INPUT")

{

obj = document.all[i+iDirection];

i+= iDirection;

if(i==-1||i>=document.all.length) return;

}

if(obj.tagName.toUpperCase() == "INPUT" && obj.type== "text" )

{

obj.focus();

//obj.select = true; //no play,why?

}

}

function GoV(iDirection)

{

var re = new RegExp(":([0-9]+):");

var sender = event.srcElement;

var name,p,newrrow,target;

if (!sender.readOnly)

{

name = sender.name;

p = re.exec(name);

if (p != null)

{

newrow = Number(p[1])+ iDirection;

target = RegExp.leftContext + ":" + newrow + ":" + RegExp.rightContext;

if (document.getElementById(target) != null)

{

document.getElementById(target).focus();

document.getElementById(target).select();

}

}

}

}

Smile.

nsqsmilea at 2007-7-12 2:53:10 > top of Java-index,Development Tools,Java Tools...