Forum Stats

  • 3,782,578 Users
  • 2,254,668 Discussions
  • 7,880,129 Comments

Discussions

IG model JavaScript loop stops at 50 records. How to loop through all the records?

ilmarsk
ilmarsk Member Posts: 38 Red Ribbon

Hello,

Apex 20.2.0.00.20; Listener 19.4.6.r1421859; Oracle 18c XE

Dabbling in IG model with JavaScript. Trying to get various counts based on the values. Stuck on model not looping past 50 records. Simplified code to show the issue is below. Loop count always stops at 50, while getTotalRecords functions returns in this case 51 records (DEMO_STATES table).

On even bigger tables I have had getTotalRecords = -1 and loop stops at 50.

How does one loop through all the records in IG table with javascript?

I am aware of PL/SQL solution, but would prefer JavaScript due to slight flickering/visible delayed update on the screen.

Thank you!

var model = apex.region("test_ig").widget().interactiveGrid("getViews", "grid").model;
var loop_cnt=0;
var get_total_cnt=0;
model.forEach(function(igrow) {
       ++loop_cnt;
       console.log(loop_cnt); 
});
 console.log("Loop count:"+loop_cnt);
 get_total_cnt = model.getTotalRecords();
 console.log("Get total count:"+get_total_cnt);


Best Answer

  • ilmarsk
    ilmarsk Member Posts: 38 Red Ribbon
    Accepted Answer

    Hello Hamza!

    Thanks for looking into this issue. Unfortunately, the setting you are referring to affects only UI. The javascript model behind the scenes are still limited to 50 records. In short, I can see 100 rows on the screen, but when trying to iterate through the IG model object I get only 50.

    However, your post prompted me to dig deeper. I found the answer here:

    See the very last section in Tomas blog. And there John's comment that points to fetchAll function!

    https://docs.oracle.com/en/database/oracle/application-express/18.2/aexjs/model.html#fetchAll


    See the working code below - for each need to be within fetchAll for this to work. I have seen so many blogs about IG iteration and none of them talk about fetchAll. Past 50 rows all those solutions have bugs!

    Thank you!

    var model = apex.region("test_ig").widget().interactiveGrid("getViews", "grid").model;
    var loop_cnt=0;
    var get_total_cnt=0;
    
    model.fetchAll(function(status){
       if (status.done) {
           model.forEach(function(igrow) {
                   ++loop_cnt;
                   console.log('row: '+loop_cnt); 
           })
    
           console.log("Loop count:"+loop_cnt);
    
           get_total_cnt = model.getTotalRecords();
           console.log("Get total count:"+get_total_cnt);
    
    
           $s("P90_TOTAL_COUNT",loop_cnt);
       }
    });
    


Answers

  • Hamza Al-abbasi
    Hamza Al-abbasi Member Posts: 219 Gold Badge
    edited Nov 16, 2021 7:51PM

    Hello ilmarsk,

    The IG renders 50 row if it's Pagination Type = Scroll, so you can change Type to Page from IG Attributes Tab and then go to IG Actions Button > Format > Rows Per Page and then choose for example 1000 row to be render. Keep in mind if there are many rows to be render the page may be render slowly.


    Hope this helps!

    Regards,

    Hamza

  • ilmarsk
    ilmarsk Member Posts: 38 Red Ribbon
    Accepted Answer

    Hello Hamza!

    Thanks for looking into this issue. Unfortunately, the setting you are referring to affects only UI. The javascript model behind the scenes are still limited to 50 records. In short, I can see 100 rows on the screen, but when trying to iterate through the IG model object I get only 50.

    However, your post prompted me to dig deeper. I found the answer here:

    See the very last section in Tomas blog. And there John's comment that points to fetchAll function!

    https://docs.oracle.com/en/database/oracle/application-express/18.2/aexjs/model.html#fetchAll


    See the working code below - for each need to be within fetchAll for this to work. I have seen so many blogs about IG iteration and none of them talk about fetchAll. Past 50 rows all those solutions have bugs!

    Thank you!

    var model = apex.region("test_ig").widget().interactiveGrid("getViews", "grid").model;
    var loop_cnt=0;
    var get_total_cnt=0;
    
    model.fetchAll(function(status){
       if (status.done) {
           model.forEach(function(igrow) {
                   ++loop_cnt;
                   console.log('row: '+loop_cnt); 
           })
    
           console.log("Loop count:"+loop_cnt);
    
           get_total_cnt = model.getTotalRecords();
           console.log("Get total count:"+get_total_cnt);
    
    
           $s("P90_TOTAL_COUNT",loop_cnt);
       }
    });