10 Replies Latest reply on Sep 19, 2018 5:42 PM by Pavel_p

    How to refresh the data in a grid

    Jeremy Webb

      Apex 5.1.4

       

      I have an interactive grid which queries an apex collection for its data.

       

      There is an option for the user to specify a different date. If they do so, an Ajax process is kicked off to repopulate the data in the collection based on the new date.

      How do I then refresh the grid to reflect the new data in the collection.

       

      Ideally I do not want to do a apex.submit as this is not a great user experience.

      Doing a region refresh does repopulate the data, however some of the column highlighting are then missing.

      The problem with doing a region refresh and then refreshing the grid is that I cannot find a way to determine when the region refresh has completed to then say now run the grid refresh, as I need to ensure that the region refresh has completed before the grid refresh happens.

       

      Tried using interactivegridsave event to capture when the region refresh has completed but this does not seem to work.

       

      Any ideas?

       

      Thanks,

       

      Jeremy

        • 1. Re: How to refresh the data in a grid
          Pavel_p

          Hi Jeremy,

          is there any special reason for AJAX process? Probably you can create a declarative DA on your date page item (or wherever needed) with two subsequent True actions - first one Execute PL/SQL code to repopulate the collection (with that date item specified as Item(s) to Submit) and then Refresh Region => Your IG region.

          Please, could you also describe in more detail why you want to refresh some other region than the IG? What regions (other than the IG) needs to be refreshed and why?

          Regards,

          Pavel

          • 2. Re: How to refresh the data in a grid
            Dharmendra Kumar-Oracle

            Please try using widget refresh method.

            apex.region("grid_id").widget().interactiveGrid("refresh");

            1 person found this helpful
            • 3. Re: How to refresh the data in a grid
              Jeremy Webb

              Hi,

               

              I need the collection to be populated before the IG is rendered. As a DA, the earliest I can run a DA is on page load which is too late.

               

              The calculations which are done and the results loaded into the collection take a fair amount of time to run, so I have two versions of the IG, in different regions which are displayed conditionally. One is for todays date, which does not require the collection as we have some MV's which give the correct data. However the users also require to be able to forecast for the future, so they can pick a date and then the calculations are done on the fly and stored into the collection. Once the collection is complete, which I have inside a javascript promise, then the appropriate IG needs to be refreshed to use the newly calculated data.

               

              Thanks,

               

              Jeremy

              • 4. Re: How to refresh the data in a grid
                Pavel_p

                I'm afraid your requirements are not clear (at least not to me).

                I need the collection to be populated before the IG is rendered. As a DA, the earliest I can run a DA is on page load which is too late.

                Ok, so run it as a before-header process (ideally encapsulate it as package.proc_load_collection(some_input_params...)), however it's still a bit confusing how it could be run before the page loads as it is supposed to take some input date parameter from the page. Either I'm getting it completely wrong or it looks like a vicious circle.

                However the users also require to be able to forecast for the future, so they can pick a date and then the calculations are done on the fly and stored into the collection.

                So far so good, that looks like a very reasonable requirement which can be done as the first PL/SQL True DA with Wait for Result attribute set to yes.

                Once the collection is complete, which I have inside a javascript promise, then the appropriate IG needs to be refreshed to use the newly calculated data.

                Which can be done as well declaratively with the second True Action (Refresh Region). I still see no reason for using advanced JS and promises.

                You can give your grid some Static ID like myIG and then use apex.region refresh JS API https://docs.oracle.com/database/apex-5.1/AEAPI/apex-region.htm#AEAPI-GUID-E876693A-3F77-4218-B5D5-94AE49C05537 to refresh it

                success: function( pData ) {
                  // do something here
                   var region = apex.region( "myIG" );
                   region.refresh();
                  }
                

                but the declarative way is recommended and seems to be simpler.

                1 person found this helpful
                • 5. Re: How to refresh the data in a grid
                  John Snyders-Oracle

                  Hi Jeremy,

                   

                  Doing a region refresh does repopulate the data, however some of the column highlighting are then missing.

                  Sounds like you have a working solution except that some column highlighting is missing. This could be a bug. Are you using the highlights feature (Actions > Format > Highlight) or something else?

                  There is this existing bug 25675608 - INTERACTIVE GRID HIGHLIGHTS NOT SHOWN AFTER SORT ON ANOTHER COLUMN but with the limited info given I have no idea if this is what you are running into.

                   

                  Perhaps the IG Cookbook Cell Style Based on Data example could be of use to you.

                   

                  The only event that may be of use to you is gridpagechange but you don't want to refresh every time it fires.

                   

                  Regards,
                  -John

                  1 person found this helpful
                  • 6. Re: How to refresh the data in a grid
                    Jeremy Webb

                    HI Pavel,

                     

                    Thanks for your help on this. From your comments I realised I had made it over complicated.

                    The simplified version is now

                     

                    1. The first time into the page the user will always see Today's data, so I do to need to populate the collection or worry about what the date page item is set to, so this is easy.

                     

                    2. For when they select a different date and press "Go" I then run

                    2.1 A javascript dynamic action which displays a div and spinner just to show them that something is happening

                    2.2 A PL/SQL process which calls a procedure which creates the collection as required with the given date

                    2.3 A javascript process which hides the div/spinner, determines whether I should be showing the today region (which does not use the collection) or the future region (which does use the collection), and then does a refresh of the appropriate region.

                     

                    However the issue I have is that

                    If I do a apex.region('my_region').refresh() then all refreshes fine, including setting the highlighting correctly, however for some reason even though I have specified to only show 10 rows per page, 20, with the original rows being duplicated.

                     

                    If I do a grid refresh then the refresh works fine but the highlighting does not get refreshed.

                     

                    To achieve the idea result I have to do a region refresh and then a grid refresh, however somehow I have to put a wait in to say to the grid refresh, wait until the region refresh has completed.

                    Obviously I can do this with a settimeout, but this is not nice, and means from a user perspective there is a noticeable delay before the grid refresh happens.

                     

                    So that goes back to my original question, although now in simplified form as described above,

                     

                    How can I refresh the region/grid so that

                    1. I only see 10 rows rather than 20 rows (the original 10 duplicated)

                    2. That the highlighting is done correctly.

                    • 7. Re: How to refresh the data in a grid
                      Jeremy Webb

                      Hi John,

                       

                      I use the following function to set the highlights on the IG columns,

                       

                      updateRecordHighlights: function(gridId, record, id) {

                                  var ig$ = apex.region(gridId).widget();

                                  var view = ig$.interactiveGrid("getViews","grid");

                                  var model = view.model;

                                  var meta = model.getRecordMetadata(id);

                                  var fields = meta.fields;

                                  var prop;

                                  var columns = JSON.parse(theColumns);  //this is just some JSON which just maps columns with their associated RAG column

                                  var colLength = Object.keys(columns.cols).length;

                                  var thisColumn;

                                  var thisRag, a;

                       

                                  //checkColumns(columns);

                                  for (a = 0; a < colLength; a++) {

                                      thisColumn = columns.cols[a].col;

                                      thisRag = columns.cols[a].ragcol;

                                 

                                      if(!fields) {

                                          fields = meta.fields = {};

                                      }

                                      if (!fields[thisColumn]) {

                                          fields[thisColumn] = {};

                                      }

                                      var theRag = model.getValue( record, thisRag);

                                      fields[thisColumn].highlight = theRag;

                                  }

                       

                      I then use the code that you mention in Interactive Grid conditional highlighting

                      so that the highlighting should be maintained when the grid is updated etc.

                      • 8. Re: How to refresh the data in a grid
                        Pavel_p

                        Hi Jeremy,

                        there is quite a few things to be done, so I would consider submitting the page (as a Submit DA with Show Processing attribute = Yes), create the collection using the Page Process and then you could use conditions to render IG regions. The page scrolls to the top anyway if the IG is refreshed, moreover you need to wait for the result and show spinner, so user experience would be more or less the same when using a DA or submitting the page, while the latter should (hopefully) solve your problems.

                        Regards,

                        Pavel

                        1 person found this helpful
                        • 9. Re: How to refresh the data in a grid
                          Jeremy Webb

                          Hi,

                          So we have now made it so that the page is far simpler, and far more done in DA's.

                           

                          However we still have the issue when I change the date, and so therefore rebuild the collection, I then need to refresh the region. However just refresh region loses the formatting, so we need to do a refresh grid as well. But if this is not done after the refresh region has completed we get duplicated rows, as described above.

                           

                          Whilst we can put a setTimeout before refreshing the grid this is not ideal as currently we have it set to 1 second, anything less than this does not always work, and even with this delay, sometimes it does not work, if the system is going very slow or lots of data is being retrieved.

                           

                          Any help on this would be gratefully received.

                           

                          Thanks,

                           

                          Jeremy

                          • 10. Re: How to refresh the data in a grid
                            Pavel_p

                            Hi Jeremy,

                            I'm afraid this does not lead anywhere, at least not towards any solution. Please, create a showcase on apex.oracle.com (if you don't have a workspace yet, create a new one) and share developer credentials. One example we could "touch" is way better than thousand words.

                            Regards,

                            Pavel