This question has been answered by multiple community members. See the first response.
var containerId = 6; // just for example
myCmp.grid.Resource = function(config) {
config = config || {};
Ext.applyIf(config,{
id: 'mycmp-grid-resource'
,url: myCmp.config.connectorUrl
,baseParams: {
action: 'mgr/mycmp/getList'
// set the 'parent' parameter for retrieval in the processor
,parent: containerId
}
// add fields you want in the grid (or record) here
,fields: ['id','pagetitle','template']
,paging: true
,remoteSort: true
,anchor: '97%'
,columns: [{
header: 'Id'
,dataIndex: 'id'
,sortable: true
},{
header: 'Pagetitle'
,dataIndex: 'pagetitle'
,sortable: true
},{
header: 'Template'
,dataIndex: 'template'
,sortable: true
}/*
Then add the columns here
*/]
});
myCmp.grid.Resource.superclass.constructor.call(this,config)
};
Ext.extend(myCmp.grid.Resource,MODx.grid.Grid);
Ext.reg('mycmp-grid-resource',myCmp.grid.Resource);
<?php
class myResourceGetListProcessor extends modObjectGetListProcessor {
public $classKey = 'modResource';
public $languageTopics = array('resource');
public $defaultSortField = 'pagetitle';
/* Override prepareQueryBeforeCount(), adding in the 'parent' clause */
public function prepareQueryBeforeCount(xPDOQuery $c) {
$parent = $this->getProperty('parent'); // we set this in the grid, remember?
if (!empty($parent)) {
$c->where(array('parent:=' => $parent));
}
return $c;
}
}
return 'myResourceGetListProcessor';
<?php
class MyExtraGetListProcessor extends modObjectGetListProcessor {
public $classKey = 'modResource';
public $languageTopics = array('myextra:default');
public $defaultSortField = 'published';
public $checkListPermission = true;
public $defaultSortDirection = 'ASC';
public $objectType = 'modResource';
public function prepareQueryBeforeCount(xPDOQuery $c) {
$parent = $this->getProperty('parent');
if (!empty($parent)) {
//as I understand this should leftJoin the users table with an alias of Users
$c->leftJoin('modUsers','Users');
//what code to add now to get the username field from the
//users table and display it in the CMP grid?
$c->where(array('parent:=' => $parent));
$c->where(array('deleted' => 0));
}
return $c;
}
}
return 'MyExtraGetListProcessor';
...
,{
header: _('myextra.resource_publisher')
,dataIndex: 'publishedby_username'
,width: 100
}
...
<aggregate alias="CreatedBy" class="modUser" local="createdby" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="EditedBy" class="modUser" local="editedby" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="DeletedBy" class="modUser" local="deletedby" foreign="id" cardinality="one" owner="foreign" />
<aggregate alias="PublishedBy" class="modUser" local="publishedby" foreign="id" cardinality="one" owner="foreign" />
$joinclass = 'modUser'; $joinalias = 'PublishedBy'; $c->leftjoin($joinclass, $joinalias);
$c->select($modx->getSelectColumns($joinclass, $joinalias, 'publishedby_'));
public function prepareQueryBeforeCount(xPDOQuery $c) {
$parent = $this->getProperty('parent');
if (!empty($parent)) {
$joinclass = 'modUser';
$joinalias = 'PublishedBy';
$c->leftjoin($joinclass, $joinalias);
$c->select($modx->getSelectColumns($joinclass, $joinalias, 'publishedby_'));
$c->where(array('parent:=' => $parent));
$c->where(array('deleted' => 0));
}
return $c;
}