Search code examples
pluginsextjs3extjs-mvcmodxmodx-revolution

How to use ExtJS plugin 'Row Expander' with a MODx grid


I'm building an extra for MODx Revolution 2.2.x which uses ExtJS 3.4 as the front end. I have a grid that I need to use the "Row Expander" ExtJS plugin with, but I'm not sure how to translate the provided example http://dev.sencha.com/deploy/ext-3.4.0/examples/grid/grid-plugins.html (It's the first example grid) into MODExt syntax.

My main issue I think is the example is using a local store and is not using class templates like MODx does.

Here's the basic example grid I'm attempting to add the plug-in to:

Example.grid.Artworks = function(config) {
    config = config || {};
    Ext.applyIf(config,{
        id: 'example-grid-artworks'
        ,url: Example.config.connectorUrl
        ,baseParams: { action: 'mgr/example/getListArtworks' }
        ,fields: ['id','name','description','menu']
        ,paging: true
        ,pageSize: 5
        ,remoteSort: true
        ,autoExpandColumn: 'description'
        ,columns: [{
            header: _('id')
            ,dataIndex: 'id'
        },{
            header: _('example.artwork_name')
            ,dataIndex: 'name'
        },{
            header: _('example.artwork_desc')
            ,dataIndex: 'name'
        }]
    });
    Example.grid.Artworks.superclass.constructor.call(this,config)
}
Ext.extend(Example.grid.Artworks,MODx.grid.Grid);
Ext.reg('example-grid-artworks',Example.grid.Artworks);

Any insight as to how to incorporate the plugin with MODx's connectorUrl and the baseParams would be greatly appreciated.

Thanks in advance.


Solution

  • Ok I managed to work it out. I'll leave this here if anyone else faces the same issue.

    Example.grid.Artworks = function(config) {
        config = config || {};
    
        // ---- This gets added here ------
        this.exp = new Ext.grid.RowExpander({
            tpl : new Ext.Template(
                '<p>{expandedcontent}</p>'
            )
        });
    
        Ext.applyIf(config,{
            id: 'example-grid-artworks'
            ,url: Example.config.connectorUrl
            ,baseParams: { action: 'mgr/example/getListArtworks' }
            // added the expanded content field here.
            ,fields: ['id','name','description','expandedcontent','menu']
            ,paging: true
            ,pageSize: 5
            ,remoteSort: true
            ,autoExpandColumn: 'description'
            ,plugins: [this.exp] // <---- add this here
            ,columns: [this.exp,{ // <----- add this here
                header: _('id')
                ,dataIndex: 'id'
            },{
                header: _('example.artwork_name')
                ,dataIndex: 'name'
            },{
                header: _('example.artwork_desc')
                ,dataIndex: 'name'
            }]
        });
        Example.grid.Artworks.superclass.constructor.call(this,config)
    }
    Ext.extend(Example.grid.Artworks,MODx.grid.Grid);
    Ext.reg('example-grid-artworks',Example.grid.Artworks);