This site is currently read-only as we are migrating to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,963 Users
  • 2,269,775 Discussions
  • 7,916,823 Comments

Discussions

Auto Refresh Grid

Chad L
Chad L OklahomaMember Posts: 8 Red Ribbon

I would like to auto refresh 1 or more Interactive Grids or Reports on a page every so often.

I'm using setInterval("jQuery('#grdMyGrid').trigger('apexrefresh');", 15000); which works. But this grid has a link that opens a modal. When the modal is open and it refreshes again, it closes the modal.

Is there a way to only refresh if a modal is not open?

Or refresh the grid without it closing the modal?

Tagged:

Answers

  • Hamza Al-abbasi
    Hamza Al-abbasi Mid-level Oracle APEX Developer Member Posts: 873 Bronze Crown
    edited Dec 3, 2021 8:18PM

    Hello Chad L,

    Set your IG or IR Static Id attribute e.g. emp then edit your JS Code as follow :

    setInterval(function(){
      apex.region('emp').refresh();
    }, 15000);
    

    Hope this helps!

    Regards,

    Hamza

  • Joe Upshaw
    Joe Upshaw Member Posts: 983 Silver Badge
    edited Dec 3, 2021 9:32PM

    Let's assume 2 things...your modal is not in the DOM when it isn't visible, i.e. it is created on the fly, and that your modal has a static ID that we can reference. For this, let's call it "MyModal".

    setInterval( 
        function()
        {   
            if( $('#MyModal').length = 0 )
            {
                apex.region('grdMyGrid').refresh();
            }        
        }, 
        15000); 
    

    If your modal stays in the DOM but, simply becomes invisible, then this code should do it:

    setInterval( 
        function()
        {   
            if( $('#MyModal').css('display') = 'none' )
            {
                apex.region('grdMyGrid').refresh();
            }        
        }, 
        15000);   
    

    Cheers,

    -Joe

  • Chad L
    Chad L OklahomaMember Posts: 8 Red Ribbon

    That works, but seems to worth the same as the way I had.

    I incorrectly said the refresh closes any open modal when it refreshes. It doesn't close the modal. But it does mess up an current editing on the modal. If the user is in the middle of editing, it's like it removes the cursor.

    I think what I really need is to only refresh when there is no modal open.

  • Chad L
    Chad L OklahomaMember Posts: 8 Red Ribbon

    Thank you for your response.

    I don't see where a modal page has a Static ID. I did try it, checking for the existence of a grid that exists on that modal page. But I get an error. "Uncaught Reference Error: Invalid left-hand side in assignment" every time it fires. Whether the modal is up or not.

    In the (base page) Function and Global Variable Declaration, I have:


    setInterval( 

      function()

      {  

        if( $('#grdPES').css('display') = 'none' )

        {

          apex.region('grdBreakdowns2').refresh();

        }     

      }, 

      5000);  

  • Joe Upshaw
    Joe Upshaw Member Posts: 983 Silver Badge

    So, if you don't have a static ID, then using will not work. It doesn't have to be a static ID. Any jQuery selector will do. You don't mention exactly how you are presenting your modal window but, assuming you are using a page with a Page Mode of "Modal Dialog," this selector will work fine:

    $('div[role="dialog"]')

    (Also, assumes you just have one modal dialog on the page). Slight bug in my JS there 😏. The equal sign is wrong for an if evaluation. Sorry about that...was typing on the fly. Assuming our new selector works, use this:

    setInterval( 
      function()
      {  
        if( $('div[role="dialog"]').css('display') === 'none' )
        {
          apex.region('grdBreakdowns2').refresh();
        }     
      }, 
      5000 );
    

    -Joe