Array of data structures to grid

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
JayGoo83
Profound User
Posts: 36
Joined: Fri Jul 17, 2020 12:52 pm
First Name: Jason
Last Name: Guzik
Company Name: 3Linc
Contact:

Array of data structures to grid

Post by JayGoo83 »

I hope this question makes sense and i apologize if it doesn't. I'm still learning...

I need to create a filtering window. I already created an array that holds a DS, with a Y/N for a checkbox and a description. I created a new screen that will function as a window and in that screen i have a grid. The screen is named "GroupFilt" and the grid is "GFSfl". The GFSfl has 2 binded fields, GRPCODEA for checkbox and GRPCODEB for the description. I already have my array loaded and the trigger will be when i click a button "filterBtn". In my backend i have the code set up for when the btn is clicked, and i have the loop over my array, i just don't know how to write to the grid and then display it.

Code: Select all

       Dcl-DS GFSfl_In LikeRec(DisplyFile.GFSfl:*INPUT) ;
       DCL-DS GFSfl_Out LikeRec(DisplyFile.GFSfl:*OUTPUt) ;
       
           FOR ix = 1 to %elem(CodesDrop);
       
              IF CodesDrop(ix)= *blank;
                leave;
              ENDIF;
       
              Clear GFSfl_Out ;
              GFSfl_Out.GRPCODEA = CodesDrop(ix).Chk ;
              GFSfl_Out.GRPCODEB = CodesDrop(ix).Code;
              Write DisplyFile.GFSfl GFSfl_Out ;
       
             ENDFOR;
       
 
If clarification is needed I will be checking this regularly. Or you can send me a direct message. Thank you in advance
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Array of data structures to grid

Post by Scott Klement »

The only thing, off the top of my head, that is missing from the code you posted is that you're not adding to the row number. (aka the "relative record number" or "RRN" for short... which is the term they use for the row number.)

In a subfile application, you define a variable on the DCL-F SFILE keyword that tracks which row you are writing to. (When reading, it'll automatically be set to the row that was read.)

For example, this DCL-F has an SFILE keyword that associates a field named RRN with a subfile record format named GFSFL.

Code: Select all

dcl-f MYFILE workstn handler('PROFOUNDUI(HANDLER)') sfile(GFSFL: RRN);
 .
 .
dcl-s RRN packed(4: 0);
When you write the rows to the grid, you'll need to set the RRN to the row you want to write. Assuming that you want the data to be written to the start of the subfile, and that you've already cleared it, then it might be as simple as just adding 1 to the RRN each time through your loop:

Code: Select all

 RRN = 0;
     
 FOR ix = 1 to %elem(CodesDrop);
       
    IF CodesDrop(ix)= *blank;
       leave;
    ENDIF;
       
    Clear GFSfl_Out ;
    GFSfl_Out.GRPCODEA = CodesDrop(ix).Chk ;
    GFSfl_Out.GRPCODEB = CodesDrop(ix).Code;
    
    RRN += 1;
    Write DisplyFile.GFSfl GFSfl_Out ;
      
 ENDFOR;
I think that's what you're asking, right? The RPG code is the same as it would be in green-screen, if that helps at all.

If not, ask some more, and I'll see if I can help.
JayGoo83
Profound User
Posts: 36
Joined: Fri Jul 17, 2020 12:52 pm
First Name: Jason
Last Name: Guzik
Company Name: 3Linc
Contact:

Re: Array of data structures to grid

Post by JayGoo83 »

Scott thank you for responding.
I didn't know about declaring the subfile so that was super helpful, as was the rrn. I am sorry about the questions as i'm learning as I go.
So what you told me did help but i have one last question. How do i get the window to actually open up and display my data now? I debugged and it looks like it is writing correctly, but what is the trigger that makes the window display on the screen?
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Array of data structures to grid

Post by Scott Klement »

Typically, you'd code something like this to display a record (windows are done the same way as other formats):

Code: Select all

exfmt MY-WINDOW-RECORD-FORMAT;
JayGoo83
Profound User
Posts: 36
Joined: Fri Jul 17, 2020 12:52 pm
First Name: Jason
Last Name: Guzik
Company Name: 3Linc
Contact:

Re: Array of data structures to grid

Post by JayGoo83 »

Thanks for answering my questions. I really appreciate it. You are a life saver
Now that i'm getting my subfile working, i have another question.

Once a page loads, do i have access to the json that was used to build the page's data? I want to do filtering similar to what happens when you right click on a column and start typing.

I don't know if i need to just yet, but also is there a way to change that json and send it back to my RPG program as an action that my program listens for? Like IF action="UPDATE"...//// code that reads JSON //// ENDIF ? Because i can do all my filtering client side just like the right clicking but i might need to update the server side array also
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Array of data structures to grid

Post by Scott Klement »

Are you referring to the JSON that was sent from the IBM i to your display file? If so, yes... you can access it... but, it will not contain any of the changes that you make by right-clicking and filtering, etc.

If you just want a JSON document that contains the current contents of the grid (and it doesn't need to be the one that was sent from IBM i) you could call the getAllDataValues() JavaScript function, and then use JSON.stringify() to convert it to JSON format.
https://docs.profoundlogic.com/x/EgGzAQ
https://developer.mozilla.org/en-US/doc ... /stringify

I'm not sure if that helps you or not, since I'm not sure what processing you wish to do with the JSON?
JayGoo83
Profound User
Posts: 36
Joined: Fri Jul 17, 2020 12:52 pm
First Name: Jason
Last Name: Guzik
Company Name: 3Linc
Contact:

Re: Array of data structures to grid

Post by JayGoo83 »

Thanks for your help Scott. Appreciate it. Went down a few rabbit holes but worked my way out.
New question though and not sure if should just make a new post:
How would i write an onclick ajax request to my RPG program? I'm reading the docs now and i can't get the API to hit my RPG program. I need to click on a checkbox, which i need to figure out how to store 3 unique keys, and then send those 3 keys plus whether checked or not back to my RPG to update/write record.
This is the API i've been trying to get working

Code: Select all

function updateRecord(){
  var ajaxRequest = new pui.AjaxRequest({
    url: "MYPROGRAM",
    method: "post",
    async: true,
    suppressAlert: true,
    params: {
      key1: "auto",
      key2: "sedan",
      key3: "honda",
      chk: "Y"
    }
  });
  ajaxRequest.send();
}
When i look at the request in the network it is sending to http://ip address/profoundui/myprogram
And once i get it to hit my program, is there something unique to let my rpg program know this is an ajax request? Before profound i would set a variable called handlAjax = 'Y' and it would listen for that variable and when true execute my subroutine
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Array of data structures to grid

Post by Scott Klement »

Please start a new thread, your question doesn't seem related to this one. I don't really understand what you're trying to do or why, so further explanation in that new thread would be helpful.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests