We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10378
    • 375 Posts
    Hi,

    I have an ExtJS grid which list categories from a custom table. Each category may have assigned a group from a second custom table. This grid can be filtered by a modx-combo which list the groups from the second table. The mods-combo gets it's data from a getlist processor.

    The problem is - additionally to the received list of groups I would need a select option "No group assigned" - to filter the grid by categories which have no group assigned.

    How can this be done?
    Is it possible to manually add a data row within the getlist processor?
    Or can I add a row in the ExtJS modx-combo although its filled by a JsonStore?

    Here is the getlist processor:

    class GroupFilterGetListProcessor extends modObjectGetListProcessor {
        public $classKey = 'GoodNewsGroup';
        public $languageTopics = array('goodnews:default');
        public $defaultSortField = 'name';
        public $defaultSortDirection = 'ASC';
        public $objectType = 'goodnews.group';
    
        public function prepareQueryBeforeCount(xPDOQuery $c) {
    
            $c->select(array(
                'GoodNewsGroup.id',
                'GoodNewsGroup.name',
            ));
            return $c;
        }
    
        public function prepareRow(xPDOObject $object) {
            $resourceArray =  $object->toArray('', false, true, true);
            return $resourceArray;
        }
        
    }
    return 'GroupFilterGetListProcessor';
    


    And here the modx-combo part:

            {
                xtype: 'modx-combo'
                ,id: 'goodnews-categories-group-filter'
                ,emptyText: _('goodnews.subscribers_user_group')+'...'
                ,width: 200
                ,listWidth: 250
                ,displayField: 'name'
                ,valueField: 'id'
                ,store: new Ext.data.JsonStore({
                    url: GoodNews.config.connectorUrl
                    ,baseParams: {
                        action : 'mgr/groups/getGroupFilterList'
                    }
                    ,fields: ['id','name']
                    ,root: 'results'
                })
                ,listeners: {
                    'select': {fn:this.filterByUserGroup,scope:this}
                }
            }
    


    Greetings,
    Martin

    This question has been answered by multiple community members. See the first response.

    [ed. note: gadgetto last edited this post 13 years, 8 months ago.]
      Freelancer @bitego http://www.bitego.com
      ---
      GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
      More infos here: http://www.bitego.com/extras/goodnews/
    • discuss.answer
      • 33976 ☆ A M B ☆
      • 571 Posts
      I guess the easiest solution would be to override afterIteration method and use array_unshift to prepend your desired data.

      Hope that will help smiley

      Edit : beforeIteration might even be better ^^
      • discuss.answer
        • 10378
        • 375 Posts
        @romain: your hint to overwrite the beforeIteration method, was the solution! Thanks! BTW - an array_unshift isn't needed as the beforeIteration method handles the insertion perfectly.

        Here are the final working code parts:

        class GroupFilterGetListProcessor extends modObjectGetListProcessor {
            public $classKey = 'GoodNewsGroup';
            public $languageTopics = array('goodnews:default');
            public $defaultSortField = 'name';
            public $defaultSortDirection = 'ASC';
            public $objectType = 'goodnews.group';
        
            public function prepareQueryBeforeCount(xPDOQuery $c) {
                $c->select(array(
                    'GoodNewsGroup.id',
                    'GoodNewsGroup.name',
                ));
                return $c;
            }
        
            public function prepareRow(xPDOObject $object) {
                $resourceArray =  $object->toArray('', false, true, true);
                return $resourceArray;
            }
        
            public function beforeIteration(array $list) {
                // additional option value "no group assigned"
                if ($this->getProperty('addNoGroupOption', false)) {
                    $list[] = array(
                        'id' => '0',
                        'name' => $this->modx->lexicon('goodnews.subscribers_no_group'),
                    );
                }
                return $list;
            }
        
        }
        return 'GroupFilterGetListProcessor';
        


                {
                    xtype: 'modx-combo'
                    ,id: 'goodnews-categories-group-filter'
                    ,emptyText: _('goodnews.subscribers_user_group')+'...'
                    ,width: 200
                    ,listWidth: 250
                    ,displayField: 'name'
                    ,valueField: 'id'
                    ,store: new Ext.data.JsonStore({
                        url: GoodNews.config.connectorUrl
                        ,baseParams: {
                            action : 'mgr/groups/getGroupFilterList'
                            ,addNoGroupOption: true
                        }
                        ,fields: ['id','name']
                        ,root: 'results'
                    })
                    ,listeners: {
                        'select': {fn:this.filterByUserGroup,scope:this}
                    }
                }
        
          Freelancer @bitego http://www.bitego.com
          ---
          GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
          More infos here: http://www.bitego.com/extras/goodnews/