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.