DISPLAY ARRAY and ON INSERT

Started by Benjamin G., June 28, 2024, 11:48:55 AM

Previous topic - Next topic

Sebastien F.

Hi Ben,

About docs you are absolutely right some hint was missing in the BDL doc.

We have now added a tip.

See attachment.

Seb

Sebastien F.

About the doc you are right, we have now added a tip, see attachment.

Seb

Benjamin G.

Remarks ...

The sample proposed by Reuben was the solution that we've initially programmed but this is not really a good solution because of sort problem ...
If you try that cod after the "on action my_insert" is validated and the array is sorted the new row "dissapear" from the screen and for the end user is very strange ...
With the "ON INSERT" the row stay at the position inserted until the display array is refreshed


Regards

Reuben B.

Quote from:  . on July 02, 2024, 02:54:55 PM
Remarks ...

The sample proposed by Reuben was the solution that we've initially programmed but this is not really a good solution because of sort problem ...
If you try that cod after the "on action my_insert" is validated and the array is sorted the new row "dissapear" from the screen and for the end user is very strange ...
With the "ON INSERT" the row stay at the position inserted until the display array is refreshed


Regards

My example probably should have a DIALOG.setCurrentRow("scr", r) at the end to set the current row in the array to the row that has just been inserted.

However you said "... and the array is sorted ...".  I would be curious as to how at this point you do your sort.  Is the user clicking slowly twice on the header to redo the sort, or are you calling array.sort() ?

You should also note  the existence of an fglprofile entry "currentRowVisibleAfterSort" https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_fglprofile_004.html.  Default value is false.  If you set this to true, add the line above to set the current row to the line just added, then after inserting the row if you redo the sort by clicking slowly twice on the column header, then I think you will see what you want to see.

If you have explicitly added an array.sort(), then you might not get results you anticipate, for the same reasons that you use DIALOG.insertRow and not array.insertElement.  Perhaps we should have a DIALOG.reapplySort so that the user does not have to slowly click twice on the header ...

Reuben




Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero

Benjamin G.

Hi,

I don't understand why with a DISPLAY ARRAY and on action handler using DIALOG.insertrow() just after arr_curr()/scr_line() returned values are different from DIALOG.getCurrentRow() and DIALOG.arrayToVisualIndex().
There is always a gap from 1 between the values ...

eg : if the cursor array is on the line number 3 arr_curr() and scr_line() return 3 but getcurrentrow()and arraytovisualindex return 4 after the insertrow()

is there any explanation about this difference ?

Regards

Sebastien F.

Benjamin,

Please provide a code example next time.

If you want to implement your own action handler to insert a row, you should do following:

Code (genero) Select
        ON ACTION myinsert
           LET x = DIALOG.getCurrentRow("sr")
display "insert row: curr = ", x
           CALL DIALOG.insertRow("sr",x)
           CALL DIALOG.setCurrentRow("sr",x)              -- MUST SET THE NEW CURRENT ROW!
display "after insertrow()"
display "  arr_curr()           = ", arr_curr()
display "  scr_line()           = ", scr_line()
display "  getCurrentRow()      = ", DIALOG.getCurrentRow("sr")
display "  arrayToVisualIndex() = ", DIALOG.arrayToVisualIndex("sr",DIALOG.getCurrentRow("sr"))


However, why are you doing this?

Is ON INSERT of DISPLAY ARRAY not good for you?

Please explain the reasons why you want to write your own action handler to insert rows.

Seb

Benjamin G.

Hi Sebastien,

The reason of using a custom action is that the user can choose between "insert one" or "insert multiple" records in the array ...
It would be nice that if we could call an "on action" programatically

eg. :

Display array .....
   on insert
       code ....
   on myaction insertone
     execute "on insert"
   on myaction insertmultiple
     while not stop
        execute "on insert"
     end while
end display

i will try with the "setcurrentrow" after insertrow ... but it seems to me not logical


regards

Benjamin G.

Hi,

calling setcurrentrow after insertrow work's ...

regards