We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    Hi, I'm working with the Teamlister addon, which is perfect for my needs but has a small problem I'm trying to fix. The problem is: when removing a record from the grid, the grid refreshes automatically, but the change is not reflected in the grid. The removed record is still there and can still be edited. Only after I edit and save another record, or the already removed record, this removed record disappears from the grid (even if I've just edited it). For my clients this can be very confusing.

    I've also asked the developer what could be the problem (https://github.com/meltingmedia/TeamLister/issues/7), and he says it's probably because I have cache_db enabled (which I have). In this topic I'm really not asking for a specific solution for this component, but I'm trying to get a better understanding of how this works with MODExt and if it's the correct behavior, or if something is wrong with my installation.

    I hope someone can explain to me why the updated info (a record is removed) is only retrieved when editing and saving a record and not after removing a record. In both situations (update and remove),
    this.refresh()
    is present in the code. To me the code looks much the same as the Doodle tutorial so I guess it's correct. What exactly triggers retrieving the new data from the DB and in what situations is the db cache cleared? Thanks!
      • 22303 MODX Staff
      • 10,725 Posts
      If the processor for TeamLister is using the API when removing the records, it should automatically remove any other cache_db entries identified by the same classname. If it is not using the remove() method, that may explain the problem. If it is, I can take a closer look at the problem.
        • 19328
        • 433 Posts
        I think it is using the remove() method, because in core/components/teamlister/processors/mgr/member/remove.php there is this:

        if (empty($scriptProperties['id'])) return $modx->error->failure($modx->lexicon('teamlister.member_err_ns'));
        $member = $modx->getObject('TeamMember',$scriptProperties['id']);
        
        if (!$member) return $modx->error->failure($modx->lexicon('teamlister.member_err_nf'));
        
        if ($member->remove() == false) {
            return $modx->error->failure($modx->lexicon('teamlister.member_err_remove'));
        }
        
        // output
        return $modx->error->success('',$member);
        
        

          • 37108
          • 80 Posts
          In a component/CMP I'm working on, this also happens when extending the modObjectRemoveProcessor [which does use the remove() method]. When the cache_db system setting is turned off, the problem disappears. Is there a way to clear the db cache via the processor?

          passcodes.grid.js snippet:
               removePasscode: function(){
                  MODx.msg.confirm({
                      title: _('passport.passcode.modal_remove'),
                      text: _('passport.passcode.modal_remove_confirm'),
                      url: this.config.url,
                      params: {
                          action: 'mgr/passcodes/remove',
                          id: this.menu.record.id
                      },
                      listeners: {
                          'success': {fn:this.refresh,scope:this}
                      }
                  });
              }
          


          processor (remove.class.php) snippet:
          class ppPasscodesRemoveProcessor extends modObjectRemoveProcessor {
          
              public $classKey = 'ppPasscodes';
              public $languageTopics = array('passport:default');
              public $objectType = 'passport.passcodes';
          
          }
          
          return 'ppPasscodesRemoveProcessor';
          
            • 3749
            • 24,544 Posts
            You can also remove the item from the grid locally with modExt assuming that you're using a selection grid. That would look something like this (in your success function, which no longer needs to call refresh).

            var sels = this.getSelectionModel().getSelections();
               if (sels.length <= 0) return false;
               var s = this.getStore();
               for (var i = 0; i < sels.length; i = i + 1) {
                   var id = sels[i].get('id');
                   var ri = id;
                   var record = s.getById(ri);
                   s.remove(record);
               }


            The down side is that if the remove processor fails, the grid may not be accurate. OTOH, the grid update will be a lot faster.

            Since you already have the Record ID and it looks like you're only removing one, this might work as well:

            var s = this.getStore();
            var ri = this.menu.record.id;
            var record = s.getById(ri);
            s.remove(record);



            or maybe just:

            var s = this.getStore();
            s.remove(this.menu.record);



            [ed. note: BobRay last edited this post 13 years ago.]
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 37108
              • 80 Posts
              Thanks for the suggestions! For clarification: I've been assuming the "success" function only runs when the removal happens without error. Is it possible to have a failure or partial failure (on a multiple delete) and still get a success response?
                • 3749
                • 24,544 Posts
                Usually not. I think it depends on what is returned in those cases by the code in the file called with Ajax.
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 22303 MODX Staff
                  • 10,725 Posts
                  The remove method should remove any cache items related to the class. This is sounding like a bug that needs to be recorded for xPDO. If anyone wants to add information to the ticket, see http://bugs.modx.com/issues/10183