We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37286
    • 160 Posts
    I am developing an extra and I am running into problems with a filter. I want to filter vehicles by the owner, which is the modx user id assigned when a user is created.

    I have my grid:
    ETRS.grid.Vehicles = function(config) {
        config = config || {};
        Ext.applyIf(config,{
            id: 'etrs-grid-vehicles'
            ,url: ETRS.config.connectorUrl
            ,baseParams: { action: 'mgr/vehicles/getList' }
            ,fields: ['vehicle_id','owner_id','vehicle_name','vehicle_description','menu']
            ,paging: true
            ,remoteSort: true
            ,anchor: '97%'
    		,columns: [{
                header: _('id')
                ,dataIndex: 'vehicle_id'
                ,sortable: true
                ,width: 60
            },{
                header: _('etrs.owner')
                ,dataIndex: 'owner_id'
                ,sortable: true
                ,width: 100
                ,editor: { xtype:'etrs-combo-users' ,renderer: true }
            },{
                header: _('etrs.name')
                ,dataIndex: 'vehicle_name'
                ,sortable: true
                ,width: 100
                ,editor: { xtype: 'textfield' }
            },{
                header: _('etrs.description')
                ,dataIndex: 'vehicle_description'
                ,sortable: true
                ,width: 100
                ,editor: { xtype: 'textfield' }
            }]		
    		,tbar:[{
    		   text: _('etrs.add.vehicle')
    		   ,handler: { xtype: 'etrs-window-add-vehicle' }
    		},'->',{
    			xtype: 'textfield'
    			,id: 'etrs-search-filter'
    			,emptyText: _('etrs.search...')
    			,listeners: {
    				'change': {fn:this.search,scope:this}
    				,'render': {fn: function(cmp) {
    					new Ext.KeyMap(cmp.getEl(), {
    						key: Ext.EventObject.ENTER
    						,fn: function() {
    							this.fireEvent('change',this);
    							this.blur();
    							return true;
    						}
    						,scope: cmp
    					});
    				},scope:this}
    			}
    		},'-',{
                xtype: 'etrs-combo-users',
                emptyText: _('etrs.filter_on.user',{what: _('user')}),
                id: 'etrs-user-filter',
                width: 200,
                listeners: {
                    'select': {fn: this.filterByUser, scope: this}
                }
            },'-',{
    			xtype: 'button',
    			text: _('etrs.clearfilter'),
    			listeners: {
    				'click': {fn: this.clearFilter, scope: this}
    			}
    		}]		
        });
        ETRS.grid.Vehicles.superclass.constructor.call(this,config)
    };
    Ext.extend(ETRS.grid.Vehicles,MODx.grid.Grid,{
        search: function(tf,nv,ov) {
            var s = this.getStore();
            s.baseParams.query = tf.getValue();
            this.getBottomToolbar().changePage(1);
            this.refresh();
        },    
        filterByUser: function (cb, rec, ri) {
            this.getStore().baseParams['owner_id'] = rec.data['id'];
            this.getBottomToolbar().changePage(1);
            this.refresh();
        },
        clearFilter: function() {
            this.getStore().baseParams['query'] = '';
            this.getStore().baseParams['user_id'] = '';
            Ext.getCmp('etrs-search-filter').reset();
            Ext.getCmp('etrs-user-filter').reset();
            this.getBottomToolbar().changePage(1);
            this.refresh();
        }
    
    });
    Ext.reg('etrs-grid-vehicles',ETRS.grid.Vehicles);
    


    I have my combo box code:
    ETRS.combo.Users = function(config) {
        config = config || {};
        Ext.applyIf(config,{
            name: 'user_id',
            hiddenName: 'user_id',
            displayField: 'display',
            valueField: 'id',
            fields: ['id','display'],
            url: ETRS.config.connector_url,
            baseParams: {
                action: 'mgr/filters/get_users_combo_filter'
            },
            typeAhead: true,
            editable: true,
            forceSelection: true,
            minChars: 1,
            pageSize: 20
        });
        ETRS.combo.Users.superclass.constructor.call(this,config);
    };
    Ext.extend(ETRS.combo.Users,MODx.combo.ComboBox);
    Ext.reg('etrs-combo-users',ETRS.combo.Users);
    


    And then the php file to get the data:
    $start = $modx->getOption('start',$scriptProperties,0);
    $limit = $modx->getOption('limit',$scriptProperties,20);
    $sort = $modx->getOption('sort',$scriptProperties,'Profile.fullname');
    $dir = $modx->getOption('dir',$scriptProperties,'asc');
    
    $c = $modx->newQuery('modUser');
    $c->innerJoin('modUserProfile','Profile');
    $c->select(array('modUser.id','Profile.fullname as fullname','modUser.username as username'));
    
    $total = $modx->getCount('modUser',$c);
    
    $c->sortby($sort,$dir);
    $c->limit($limit,$start);
    
    $results = array();
    $query = $modx->getCollection('modUser',$c);
    foreach ($query as $r) {
        $ta = $r->toArray();
        $results[] = array(
            'id' => $ta['id'],
            'display' => $ta['fullname'] . ' (' . $ta['username'] . ')'
        );
    }
    
    if (count($results) == 0)
        return $modx->error->failure($modx->lexicon('etrs.error.noresults'));
    	
    $returnArray = array(
        'success' => true,
        'total' => $total,
        'results' => $results
    );
    return $modx->toJSON($returnArray);
    


    When clicking on the combo box, nothing appears to happen, no drop down.
      • 28215
      • 4,149 Posts
      Any errors in core/cache/logs/error.log?
      What is the response sent back by the AJAX request?
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 37286
        • 160 Posts
        Nothing in the error log, but using firebug I did see the below error when I click on the drop down.

        this.proxy is undefined
        www.mydomain.com/manager/assets/ext3/ext-all.js
        Line 7
          • 37286
          • 160 Posts
          Finally got it, one alpha character out of place...
            • 37377
            • 64 Posts
            How do you define "emptyText: _('etrs.filter_on.user',{what: _('user')})," I tried altering it to my needs but when no value is selected, it says 'undefined' in the combobox.

            Thanks
              • 33968
              • 863 Posts
              You can either enter plain text:
              emptyText: 'Your Text Here'
              

              or use a lexicon key and enter text for each language in your lexicon file. More on how to do that here:
              http://rtfm.modx.com/display/revolution20/Developing+an+Extra+in+MODX+Revolution%2C+Part+II#DevelopinganExtrainMODXRevolution%2CPartII-Lexicons
                • 37377
                • 64 Posts
                Thanks, I copied the lexicon from the search textfield which had ... behind it, and that didn't seem to work for a custom combobox. But it works now.