Focal Point
Reposition a Maintain Grid on a desired row

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/5881075222

April 09, 2007, 12:58 PM
KentO
Reposition a Maintain Grid on a desired row
I need to search a maintain grid for a desired record and, when found, reposition the grid to show that row. I have the following VBScript code as my search button event.

Sub OnButton1_Click ( )
IWCTrigger "Find_Detail", "RowN"
s9_Form.Grid1.SetCurrentRow s9_Form.TriggerValue
s9_Form.Grid1.RedrawAll
End Sub

Find_Detail finds the desired row and places it in RowN, but the grid always displays starting at row 1. Is my coding wrong or do I need to uses a different technique.

Kent


Windows2003 Server, WebFOCUS 7.7.02 Developers Studio and MRE
April 09, 2007, 04:02 PM
Alan B
Kent

I have never used the grid in real life (I need to have maintains run in Firefox), so I cannot answer directly as to how to achieve what you want.

However, the logic you are using looks problematic. The IWCTrigger passes control back to the maintain on the server. The lines in the script following that will not run, because when maintain passes control back to the user page, it is a new page and does not know that you were in the middle of a script; it starts totally afresh again.

If Find_Detail could populate a hidden input with a row number, perhaps you could attach a script to run an onload event that would then set the grid to the value taken from the hidden input.


Alan.
WF 7.705/8.007
April 09, 2007, 06:04 PM
Lusheng
You should use javascript or vbscript to loop thought all cells. Within the loop, you get the value from the cell(or row) and compare, if the comparison satifies you, then you set focus to that cell.

As Alan mentioned, IWCTrigger is the way javascript talks to Maintain functions, which will not fulfil your goal.
April 10, 2007, 04:12 AM
Alan B
Kent

To put a bit more explanation on my previous response.

In your Sub OnButton1_Click event, just have the IWC_Trigger call.
Declare a variable called rowNumber/i4;
In Find_Detail, set rowNumber value to the row number that your search found.
Add an edit box onto your form, initial text to rowNumber, visible parameter to No and call it RowValue.
Create a js file and attach it to the form s9_Form.
In the js file have:
  
function showRow() {
var x=document.getElementById("RowValue").value;
s9_Form.Grid1.SetCurrentRow s9_Form(x);
s9_Form.Grid1.RedrawAll;
}
document.onload=showRow();


Note:
Changed window.onload to document.onload, as window.onload is causing an issue with maintain.

This message has been edited. Last edited by: Alan B,


Alan.
WF 7.705/8.007
April 10, 2007, 09:34 AM
Maintain Wizard
All
I realize that this doesn't add to the "Setting a Row in a Grid conversation", but I am adding this small doc on SetCancelFlag here. When a user tabs out of a cell, use SetCancelFlag after checking the validity of the data and to determine if the cursor needs to be returned to the cell. I will write this up in the next WebFOCUS Newsletter, but for now, it is all here.

Mark

The "OnEditFinish" Grid event, which is triggered when the user moves off a cell after an edit, can be used to control the value of the current cell by coding the SetCancelFlag function with different parameters:.
• When the parameter passed to this function is Zero (0) the application is unable to use the OnEditFinish event to restrict the contents of the current cell; any value is accepted from the user. This is the default setting.

• When the parameter passed to this function is One (1) the application is able to use the OnEditFinish event to prevent the user from entering an undesirable value for the current cell while allowing them to continue to try other values.
Example: if (text == "MAYBE")
{
Form1.Grid1.SetCancelFlag(1);
alert("Invalid value - please try again");
}

• When the parameter passed to this function is Two (2) the application is able to use the OnEditFinish event to prevent the user from entering an undesirable value for the current cell, and no further user action is allowed on the cell at that time. It can be used with CellSetText or QuickSetText to automatically change the contents of the current cell to a specific value, or else it will automatically revert to the original value.

Example: if (text == "MAYBE")
{
Form1.Grid1.SetCancelFlag(2);
Form1.Grid1.GetCell(col,row);
Form1.Grid1.CellSetText("NO");
Form1.Grid1.SetCell(col,row);
Form1.Grid1.RedrawCell(col,row);
alert("Invalid value - changing to NO");
}
June 14, 2007, 03:24 PM
John_Edwards
Don't take this the wrong way or anything, but are you kidding me? This is the only way to move the grid from a Maintain trigger?

J.



June 14, 2007, 04:20 PM
Alan B
John,

Not kidding at all, based on Kent's original approach. That's 5 lines of extra JS code, which in the world of JS is not exactly overload.

It could be done all in JS rather than reverting back to the server of course.

Remember that the grid is an ActiveX control and therefore cannot be accessed as easily by JS, as, say, an HTML table, and has it's own rules.

Just out of interest what approach would you like to see?


Alan.
WF 7.705/8.007
June 19, 2007, 10:07 AM
John_Edwards
This works and does not return to the server to function. Note that my grid on the screen is 14 rows tall -- that's why there's all the futzing with 14 in the bottom half of the function.

function OnButtonFindSite_Click ( ) {
var GridLength = Counselor_List.Grid1.GetNumberRows();
var row = 0;
var found = false;
while (row < GridLength && found==false)
{
Counselor_List.Grid1.GetCell(0,row);
var CellValue=Counselor_List.Grid1.CellGetText();
if (Counselor_List.Grid1.CellGetText() == Counselor_List.EditRecordLookup.value)
{
found = true;
}
else row++;
}

if (found)
{
var NewGridPosition=row+14; // 14 moves desired record to top of the grid.
if (NewGridPosition < 14)
NewGridPosition=row; // Handles case where New Grid Position is on first page -- no offset needed.
if (NewGridPosition > GridLength)
NewGridPosition=GridLength; // Makes sure New Grid Position isn't bigger than the grid.
Counselor_List.Grid1.SetCurrentRow(0);
Counselor_List.Grid1.RedrawAll;
Counselor_List.Grid1.SetCurrentRow(NewGridPosition);
Counselor_List.Grid1.RedrawAll;
}
else
alert("That counselor number does not exist in the table.");
}



June 27, 2007, 12:46 PM
KentO
Thank you John Edwards. Your coding was almost exactly what I needed.
Kent


Windows2003 Server, WebFOCUS 7.7.02 Developers Studio and MRE
July 27, 2007, 01:46 PM
KentO
Can someone who knows JavaScript tell me how to change the following Grid search so it is case-insensitive:

function OnSearchButton_Click ( ) {
var GridLength = s9b_Perpetual_Billing.Grid1.GetNumberRows(); // JavaScript Code
var row = 0;
var found = false;
while (row < GridLength && found==false)
{
s9b_Perpetual_Billing.Grid1.GetCell(2,row);
var CellValue2=s9b_Perpetual_Billing.Grid1.CellGetText();
s9b_Perpetual_Billing.Grid1.GetCell(3,row);
var CellValue3 = s9b_Perpetual_Billing.Grid1.CellGetText();
var CellValue = (CellValue2 + CellValue3);
var Searchv = CellValue.search(s9b_Perpetual_Billing.SearchValue.value)
if (Searchv >= 0)
{
found = true;
}
else row++;
}

Thanks, Kent


Windows2003 Server, WebFOCUS 7.7.02 Developers Studio and MRE
July 27, 2007, 02:05 PM
John_Edwards
Javascript's toUpperCase is the key to your lock. Roll both sides of your comparison (not sure what your code does) to uppercase with this function and you should get a match.

J.

Reference: http://www.w3schools.com/jsref/jsref_toUpperCase.asp