Focal Point
[Solved] Js Grid on Maintain form loses data when returning to webfocus

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

October 11, 2017, 01:43 PM
Deana
[Solved] Js Grid on Maintain form loses data when returning to webfocus
I am using 7.7.03 for this application.

I have a javascript grid on a maintain form. I have 1 column (comments) which is 750 characters; 1 column (fund) which must match the values in a drop-down list; 1 update indicator column, a handful other columns which can be modified directly within the grid and several read-only columns.

In order to allow the user to view all (or at least most) of the data on the screen, I have added a multi-line text box below the grid. When I change the information in the text box, I have a function which appears to successfully modify the data in the comments column.

I also have a drop-down list on the form for the second column. Using javascript, I successfully populate the correct column in the grid.

I manually change the regular editable columns directly within the grid.

Whenever I change the data in the grid, regardless of the method, the indicator column gets set to 'Y';

However, when I call a maintain function to update the records with changed data, the changes I made using the text box and drop-down are wiped out. The changes made directly within the grid are maintained. The values for the comments and fund columns revert to the original data. If I made changes directly within the grid, the indicator column value is maintained. If I only change the comments and/or fund columns, the indicator value reverts to what is was before.

If I change the comments and fund columns directly within the grid, the values are maintained.

I read an article by Mark which shows how to add a radio box to the columns within a grid, but I did not understand how to apply that to a drop-down which is populated with data from a table.

Any assistance is appreciated.

Deana

This message has been edited. Last edited by: Deana,


WebFOCUS 7.6.8 and 7.7.03; Windows Server 2003 R2 and Windows Server 2008 R2, respectively; Development environments - Windows Server 2003 R2 and Windows 7 Professional, respectively;
excel, html, pdf
October 12, 2017, 08:21 AM
Maintain Wizard
When the user makes a selection from the drop box or enters data into the multi-line edit box I assume you are using JavaScript to take that value and place it into the grid? I would expect:
CellSetText(col, row, text);
If you are, are you setting the indicator there or are you expecting the OnCellChange event to fire? Maybe the JS command is not activating the OnCellChange event. Try updating the indicator field using CellSetText.

Any value set in a cell field using JS SHOULD get passed back to the server in the stack. I have created a simple test in 8.0 that shows that. I can send you that example and an example on how to place a dynamic list box in a grid cell. Let me know where to send it.

Mark
October 12, 2017, 10:23 AM
Deana
Mark,

Thank you for your reply. Yes I am using javascript to populate the datagrid columns.

To set the indicator flag I use
dg.CellSetText (0, currRow, "Y");. Currently it is only being set in the onCellChange event which I have verified is fired when I use dg.CellSetText (18, currRow, "Text"); I did try setting the indicator flag on the comments change event. Either way the indicator flag column is set to "Y" and the comments column is updated... until I trigger a WebFocus method.

I would appreciate your samples. My email is deana.goeken@wyo.gov.

Thank you,
Deana


WebFOCUS 7.6.8 and 7.7.03; Windows Server 2003 R2 and Windows Server 2008 R2, respectively; Development environments - Windows Server 2003 R2 and Windows 7 Professional, respectively;
excel, html, pdf
October 12, 2017, 03:41 PM
Deana
Mark,

Thank you for your samples. I was able to play around with your code and add my code until I was able to replicate my error, which led to a solution. If I manually set the row value, the data is retained. However, when I try to set the row dynamically based on the value in text box on the form, the values in the grid were not retained.

original code
var dg = document.form1.Grid2;
var currRow = document.form1.txtLastRow.value;
document.Form1.Grid2.CellSetText (1, currRow , document.Form1.MultiEditBox2.value);
document.Form1.Grid2.CellSetText (0, currRow , "Y"); //sets the indicator field value

I tried changing currRow to grid2.GetCurrentRow using both of the following samples
document.Form1.Grid2.CellSetText (1, grid2.GetCurrentRow(), document.Form1.MultiEditBox2.value);

and
var dg = document.form1.Grid2;
var currRow = grid2.GetCurrentRow();
document.Form1.Grid2.CellSetText (1, currRow , document.Form1.MultiEditBox2.value);
document.Form1.Grid2.CellSetText (0, currRow , "Y"); //sets the indicator field value

Both of the above examples worked for the first time I tried to update the comments or the fund, but the grids current row was resetting to 0 after that. Thus the next time I tried to modify either field, it was always trying to update row 0, instead of the correct row. This behavior is the reason I have a separate control on the form to track my current row to begin with. My solution is:

working code
var dg = document.form1.Grid2;
var lastRow = document.form1.txtLastRow.value;
dg.SetCurrentRow(currRow);
var currRow = dg.GetCurrentRow();
document.Form1.Grid2.CellSetText (1, currRow , document.Form1.MultiEditBox2.value);
document.Form1.Grid2.CellSetText (0, currRow , "Y"); //sets the indicator field value


WebFOCUS 7.6.8 and 7.7.03; Windows Server 2003 R2 and Windows Server 2008 R2, respectively; Development environments - Windows Server 2003 R2 and Windows 7 Professional, respectively;
excel, html, pdf