The Company
Products
Solutions
Services and Support
Customers
Partners
News
Events
Home >> News >> WebFOCUS Newsletter >> December 2003 >> Setting the Top Row of an HTMLTable

Setting the Top Row of an HTMLTable

By Mark Derwin

When an HTMLTable is displayed on a Maintain form, it always shows the first screen of data. If your user scrolls down and makes a selection, the next time the form is displayed, the HTMLTable is reset to row one.

There may be times when you want to display the currently selected row when you return to the screen. The technique I am about to show you allows that to happen.

The key to the technique is that we store the selected row in a variable and place it on the form. When the form is displayed, or redisplayed, we check the value of that variable and using JavaScript, scroll to that line.

Follow these steps to make this work:

1. In TOP Case create a variable to store the selected or starting row of the HTMLTable:
Compute Rowx/i3=1;
2. Place this field somewhere on the form. (The field does not have to be visible.)
3. In the case that is performed after making selections, add the line:
Compute Rowx = Form1.HTMLTable1.ClickRow;
4. Create another object that can have a FOCUS trigger (button, field) and place it on the form.
5. Set it as first in the tab order.
6. Place the following code on the FOCUS Trigger:
var Row1 = document.Form1.Rowx_Edit.value;
var TableDiv = document.getElementById("HTMLTable1");
var TableObj;
for(i=0; <TableDiv.children.length; i++)
{
if(TableDiv.children[i].tagName == "TABLE")
{
TableObj = TableDiv.children[i];
break;
}
}
TableObj.rows(Row1-1).scrollIntoView(true);

You will have to replace the following:

Form1 with the name of your form
HTMLTable1 with the name of your HTMLTable

When the form is displayed, control goes to the first item in your tab order as set in Step 5. When it gets FOCUS, the trigger set in Step 6 activates. This automatically scrolls the HTMLTable to the row set in Step 3.

I hope this technique assists you in using the HTMLTable to create robust Maintain applications.