5 Replies Latest reply on Aug 8, 2019 9:37 PM by Rick-Pick

    Refresh Detail Interactive Grid with new data

    Rick-Pick

      In a master-detail IG, details added by a server process - after initially accessing the page - are not displayed when selecting the master record - until I refresh the whole page.

       

      Is it possible to refresh the Detail grid to pick up new data from the server without submitting the page? A normal region refresh doesn't do this. I have tried several methods mentioned in other threads and IG blogs.

       

      Thanks,

      Rick

        • 1. Re: Refresh Detail Interactive Grid with new data
          John Snyders-Oracle

          Hi Rick,

          How are you doing the refresh. I tried it with the Sample Interactive Grids app Edit: Master Detail page and it worked using

           

          apex.region("emp").refresh(); // change "emp" to your detail IG region static id.

           

          The user can always explicitly refresh with Actions > Data > Refresh

          You can do the same with:

           

          apex.region("emp").call("getActions").invoke("refresh");

           

          but it is really the same as the simpler statement above.

           

          You may also want to set the cache size as well.

          when the page loads call

          apex.model.setMaxCachedModels(1);

          With the cache size set to 1 as long as you don't go back and forth between two master records it will always get new data.

          There is an issue that keeps you from being able to set the cache size to 0.

           

          Regards,
          -John

          1 person found this helpful
          • 2. Re: Refresh Detail Interactive Grid with new data
            Rick-Pick

            Hi John,

             

            First thank you for your helpful reply. I know it was a while ago, but I had given up on this and resorted to a page refresh to resolve the issue. However, I still have the problem since my rather complex app is under testing and this is one of the issues that has been raised.

             

            I think I now understand a bit better the behaviour of the master-detail Interactive Grids. The key is in your reply - "... as long as you don't go back and forth between two master records...". (That is exactly what the users will do in this app and I can't control that.) I had seen that "detail" data isn't refreshed after the first time you select its master record. But what if another user (or in my case a background process) has added new detail records in the meantime? These are not displayed unless the detail data is refreshed by the user after the master record is selected.

             

            The behaviour I need is that the detail data is refreshed every time its master record is selected. There are only ever a small number of records in the detail and it doesn't take too long. I think from your reply that what I need is to set the cache size to 0, but unfortunately, as you say, that isn't working. I have tried an explicit refresh every time the master record changes, but that really messes things up. After the first time, a javascript error appears - Cannot read property 'serverOffset' of null - and no details are displayed at all.

             

            One of my server processes creates new records in the detail of the currently selected master record and this works fine. A normal region refresh displays the new data. The issue occurs with a process that copies "components" - the detail records - from one master item to one or more others, of course changing the master key and record id values of the component records. This is where only a page refresh really works, but of course it is a bit ugly and long-winded.

            I'm fairly sure this cannot be an unusual requirement. In a multi-user situation wouldn't the user want to see any details added by someone else as soon as possible?

             

            Again, thank you for your responses. I wouldn't have been able to achieve anything close to the company's requirements without your many blogs and explanations. They are actually very happy with the results, and one of the IG apps that has gone live - not this one - is a great success.  It is just this one issue which is bugging me.

             

            Regards,

            Richard

            • 3. Re: Refresh Detail Interactive Grid with new data
              John Snyders-Oracle

              Hi Richard,

              This is interesting and trickier than one would expect it to be.

              Because the detail IG has a 300 ms debounce delay before changing the detail model to match the new selected master record, if you do a simple refresh on master selection change you will actually be refreshing the previous detail not the new one. In addition I also got a JavaScript error but it was different than the one you report and only happened some times. What version of APEX?

               

              I hope in the future I can fix the issue with setting the max cached models to zero. Until then I think the following should work. Add this code to the JavaScript action of a selection change event on the master IG.

               

              var detailModelName, detailModel,

                  selRecs = this.data.selectedRecords,

                  masterModel = this.data.model,

                  rec = null;

               

              if ( selRecs.length === 1 ) {

                  rec = selRecs[0];

                  detailModelName = [apex.region("emp").call("getCurrentView").model.name, masterModel.getRecordId(rec)]; // change emp to be your detail static ID

                  detailModel = apex.model.get(detailModelName);

                  if ( detailModel ) {

                      detailModel.clearData();

                      apex.model.release(detailModelName); // don't forget to release any models you get

                  }

              }

               

              What this does is when the master selection changes it finds the model that will soon be used for the detail IG and if it exists clears the data so that new data will be fetched as soon as the detail IG uses it.

               

              FYI There is also an option in 19.1 trackParentSelection, and method setMasterRecord that can be used to have full control over when the detail IG switches to the master record. There is an example of its use in IG Cookbook but you would still need to clear the data of the detail model as shown above so I don't think this would be helpful in your case.

               

              Regards,

              -John

              1 person found this helpful
              • 4. Re: Refresh Detail Interactive Grid with new data
                Rick-Pick

                Ah, thank you. We are on Apex 19.1 and will shortly upgrade to 19.2.

                 

                I have put your code in and it does seem to work, in spite of the fact I get an error the first time a master record is selected. The error is Uncaught TypeError: Cannot read property 'length' of undefined.

                 

                I am thinking though that I may not need to get the length in this case because the master grid is set to single selection mode - only one record can be selected at a time. Or perhaps I can get the model explicitly rather than by using "this".

                 

                Anyway, it does look like this could be the answer!

                 

                Regards,

                Richard

                • 5. Re: Refresh Detail Interactive Grid with new data
                  Rick-Pick

                  Hi John, here is the code I have got now on the selection change event. This executes without errors (bearing in mind that only one record can be selected at a time):

                   

                  var g = apex.region("est").call("getViews","grid"),

                  sr = g.getSelectedRecords(),

                  rec,

                  masterModel = this.data.model;

                   

                  if ( typeof sr[0] != "undefined" ) {

                   

                      // removed section which sets some page item values

                    

                      rec = sr[0];

                      detailModelName = [apex.region("cost-items").call("getCurrentView").model.name, masterModel.getRecordId(rec)]; // change emp to be your detail static ID

                      detailModel = apex.model.get(detailModelName);

                   

                      if ( detailModel ) {

                          detailModel.clearData();

                          apex.model.release(detailModelName); // don't forget to release any models you get

                       }

                  }

                   

                  This is working well in this situation. Your help is very much appreciated.

                   

                  Thanks,

                  Richard