<![CDATA[ [Solved] Custom LocalGrid - enableRowBody Not Being Applied - MODX Community Forums]]> https://forums.modx.com/thread/?thread=104772 <![CDATA[ [Solved] Custom LocalGrid - enableRowBody Not Being Applied]]> https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563429
I have made a custom resource class and have used the loadCustomCssJs function in my create controller to add a customised version of the create resource form which allows me to add the fields in my custom resource classes related tables.

The resource represents an event. I have added a grid to allow users to add multiple pricing for various vendors selling tickets.

My code for the extended LocalGrid I am using is:

rdBoxOffice.grid.Prices = function(config){
    config = config || {};

    this.exp = new Ext.ux.grid.RowExpander({
        tpl : new Ext.Template('test')
    });
    

    Ext.applyIf(config,{
        id: 'rdboxoffice-grid-prices'
        ,url: rdBoxOffice.config.connectorUrl
        ,baseParams: { action: 'mgr/prices/getList' }
        ,pluralText: 'Prices'
        ,singleText: 'Price'
        ,preventRender:true
        ,autoHeight:true
        ,viewConfig: {
          deferEmptyText: false

          ,enableRowBody: true
        }
        ,tbar: [
            {
                title: _('listing_create_price'),
                text: _('listing_create_price'),
                handler: this.addPrice
            }
        ]
        ,fields: [
            'id'
            ,'vendor_id'
            ,'fullname'
            ,'regular'
            ,'vip'
            ,'student'
        ]
        ,paging:false
        ,remoteSort: false
        ,plugins: [this.exp]
        ,columns: [this.exp,{
            header: _('listing_prices_vendor')
            ,dataIndex: 'fullname'
            ,sortable: true
            ,width: 100
        },{
            header: _('listing_prices_regular')
            ,dataIndex: 'regular'
            ,sortable: true
            ,width: 100
        },{
            header: _('listing_prices_vip')
            ,dataIndex: 'vip'
            ,sortable: true
            ,width: 100
        },{
            header: _('listing_prices_student')
            ,dataIndex: 'student'
            ,width: 100
        }]
    });
    rdBoxOffice.grid.Prices.superclass.constructor.call(this,config);
};
Ext.extend(rdBoxOffice.grid.Prices,MODx.grid.LocalGrid)


In my create resource form I have added it as so:
{xtype:'rdboxoffice-grid-prices'}


To initially load some default pricing into the grid I have used the following code in the setup function for the resource panel - it works fine:

var pricesStore = Ext.getCmp('rdboxoffice-grid-prices').getStore();
record = new pricesStore.recordType({vendor_id:sitevendorid,fullname:'Website',regular:0,vip:0,student:0});
record.commit();
pricesStore.add(record);
pricesStore.commitChanges();


The panel is displayed and the default pricing loaded with the expand button showing that the row is contracted but when I look at the markup produced in the web developer console, there is no second row in the markup and therefore when clicking the expand button, I get an error because the row can't be found to add the compiled template.

Besides explicitly setting the enableRowBody config to true, I also note that the MODX derived grids all have enableRowBody set to true in their default configs but the grid is behaving as it's set to false. To confirm this I edited the ext-all.js file and modified the only mention of enableRowBody in there to output a string if enableRowBody is false. That string is output in my grid so somehow that config option is getting changed but I've no idea how.

I was wondering whether the way I was adding the record to the store was the problem but adding the data using loadData does display the data in the grid with the expand button but once again, no second row in the table holding the columns.

Update
I modified the ext-all.js file to set the enableRowBody configuration to true and that makes my grid work as expected with the second row added and my rowexpander works. That seems to suggest some kind of problem with the config being passed back to Ext.grid.Grid.

I'm open to all suggestions as to how to take this further.]]>
freelancewebdev Jan 04, 2019, 12:58 AM https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563429
<![CDATA[Re: [Solved] Custom LocalGrid - enableRowBody Not Being Applied]]> https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563465
I can also confirm that even if I set the enableRowBody option on the resource group grid to false, that still doesn't prevent me setting it to true on my own grid, i.e. the resource group grid doesn't interfere with my own grid in the same way the MIGX one does. I can only conclude that somehow, MIGX is preventing normal inheritance in this instance.]]>
freelancewebdev Jan 06, 2019, 08:13 PM https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563465
<![CDATA[Re: Custom LocalGrid - enableRowBody Not Being Applied]]> https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563458
Viewing the source script produced by MIGX for its grids, it's not immediately apparent to me why it would be preventing the enableRowBody config to pass up the superclass chain but I wonder if it might have something to do with the grid being added to the MODx object grids object at the same level as LocalGrid in the superclass chain even though the multitv grids extend from LocalGrid. I'm surprised that MIGX didn't have it's own component object like all the other extras I've looked at. Seems like there may be the possibility for multitv grid, which has enableRowBody not explicitly set and therefore false, to be writing that config option back to the localGrid superclass after other grid classes like mine and the resource group grids but before the grids are all rendered. The behaviour does suggest that both my grid and the MIGX one are sharing the same LocalGrid instance.

Anyway, I've opened an issue on Github at:

https://github.com/Bruno17/MIGX/issues/330]]>
freelancewebdev Jan 05, 2019, 06:04 PM https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563458
<![CDATA[Re: Custom LocalGrid - enableRowBody Not Being Applied]]> https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563455 freelancewebdev Jan 05, 2019, 11:57 AM https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563455 <![CDATA[Re: Custom LocalGrid - enableRowBody Not Being Applied]]> https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563447
Also, remember that you can use addHTML() for your JS script as long as the JS code begins and ends with script tags.

The regClient...() methods will adapt to the presence or absence of script tags. It's too bad the new controller methods won't do the same.]]>
BobRay Jan 04, 2019, 06:05 PM https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563447
<![CDATA[Re: Custom LocalGrid - enableRowBody Not Being Applied]]> https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563443
Guess I'll have to keep digging....]]>
freelancewebdev Jan 04, 2019, 04:23 PM https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563443
<![CDATA[Re: Custom LocalGrid - enableRowBody Not Being Applied]]> https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563433
Thanks for the help.

Here's where I'm pushing in the config by overriding the loadCustomCssJs function.

public function loadCustomCssJs() {
      $sitevendor = $this->modx->getObject('modUser',array('username' => 'rdvendor'));
      $sitevendorid = $sitevendor->get('id');
      $this->rdBoxOffice = new rdBoxOffice($this->modx);
      $mgrUrl = $this->modx->getOption('manager_url',null,MODX_MANAGER_URL);
      $myUrl = $this->modx->getOption('assets_url').'components/'.$this->namespace.'/';
      $this->addJavascript($mgrUrl.'assets/modext/widgets/element/modx.panel.tv.renders.js');
      $this->addJavascript($mgrUrl.'assets/modext/widgets/resource/modx.grid.resource.security.local.js');
      $this->addJavascript($mgrUrl.'assets/modext/widgets/resource/modx.panel.resource.tv.js');
      $this->addJavascript($myUrl.'js/mgr/rdboxoffice.js');
      $this->addJavascript($myUrl.'js/widgets/venues/rdboxoffice.combo.venues.js');
      $this->addJavascript($myUrl.'js/widgets/plans/rdboxoffice.combo.plans.js');
      $this->addJavascript($myUrl.'js/widgets/vendors/rdboxoffice.combo.vendors.js');
      $this->addJavascript($myUrl.'js/widgets/prices/rdboxoffice.grid.prices.js');
      $this->addJavascript($myUrl.'js/widgets/resource/modx.panel.rdlistingresource.js');
      $this->addJavascript($myUrl.'js/sections/resource/create.js');
      $this->addHtml('
      <script type="text/javascript">
      // <![CDATA[
      var sitevendorid = '.$sitevendorid.';
      MODx.config.publish_document = "'.$this->canPublish.'";
      MODx.onDocFormRender = "'.$this->onDocFormRender.'";
      MODx.ctx = "'.$this->ctx.'";
      Ext.onReady(function() {
          rdBoxOffice.config = '.$this->modx->toJSON($this->rdBoxOffice->config).';
          MODx.load({
              xtype: "modx-page-resource-create"
              ,record: '.$this->modx->toJSON($this->resourceArray).'
              ,publish_document: "'.$this->canPublish.'"
              ,canSave: "'.($this->modx->hasPermission('save_document') ? 1 : 0).'"
              ,show_tvs: '.(!empty($this->tvCounts) ? 1 : 0).'
              ,mode: "create",
          });
      });
      // ]]>
      </script>');
      /* load RTE */
      parent::loadRichTextEditor();
    }


Looking at the source it seems that my Ext.onReady function is being added after the modx.grid.js file is added via a script tag. I assumed anyway that because the script doesn't run until Ext.onReady that all the scripts would be loaded into the DOM before anything ran . I can't swap out addHtml for addLastJavascript as addLastJavascript requires an external URL.

Still, it feels like you're on to something here because if I swap out all my custom js component files with addLastJavsacript rather than addJavascript, I get a bunch of errors in the console which I wouldn't have expected either since they're not being used until Ext.onReady.
]]>
freelancewebdev Jan 04, 2019, 06:38 AM https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563433
<![CDATA[Re: Custom LocalGrid - enableRowBody Not Being Applied]]> https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563432 BobRay Jan 04, 2019, 05:38 AM https://forums.modx.com/thread/104772/custom-localgrid---enablerowbody-not-being-applied#dis-post-563432