We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28215
    • 4,149 Posts
    Add a method firing on the 'show' event of the window with the scope of the window that does:

    <pre>Ext.getCmp('id-of-my-grid').getStore().loadData(mydatavalues);</pre>
      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
      • 37286
      • 160 Posts
      I'm sorry, I'm having trouble figuring out how the loaddata part works with the code I already have.
        • 37286
        • 160 Posts
        I gave up on this many months ago. Today I ran into an instance where I needed this functionality and I couldn't find a good work around. It took several hours, but I found a method that works to auto refresh a grid inside a modal window.

        I abbreviated the code some to make it a little easier to read.
        Doodle.grid.DoodleList = function(config) {
            config = config || {};
            Ext.applyIf(config,{
                id: 'doodle-grid-doodlelist'
                ,url: Doodle.config.connectorUrl
                ,baseParams: {
                    action: 'mgr/doodle/getlist'
                }
                ,fields: ['id','DoodleName','menu']
                ,paging: true
                ,remoteSort: true
                ,anchor: '97%'
                ,autoExpandColumn: 'DoodleName'
                ,columns: [{
                    header: 'Doodle Name'
                    ,dataIndex: 'DoodleName'
                    ,sortable: true
                    ,width: 30
                }]
                ,getMenu: function() {
                    return [{
                        text: 'Doodle Options'
                        ,handler: this.viewOptions
                    }];
                }
                ,viewOptions: function(btn,e) {
                    if (!this.updateDoodleListWindow) {
                        this.updateDoodleListWindow = MODx.load({
                            xtype: 'doodle-window-doodlelist'
                            ,record: this.menu.record
                            ,listeners: {
                                'success': {fn:this.refresh,scope:this}
                            }
                        });
                    }
        
                    this.updateDoodleListWindow.setValues(this.menu.record);
                    this.updateDoodleListWindow.show(e.target);
                    var optionsgrid = Ext.getCmp('doodle-grid-doodleoptions');
                    optionsgrid.store.load({params:{doodle_id: this.menu.record.id || 0}});
                }
            });
            Doodle.grid.DoodleList.superclass.constructor.call(this,config)
        };
        Ext.extend(Doodle.grid.DoodleList,MODx.grid.Grid);
        Ext.reg('doodle-grid-doodlelist',Doodle.grid.DoodleList);
        
        Doodle.window.UpdateDoodle = function(config) {
            config = config || {};
            Ext.applyIf(config,{
                title: _('doodle.update')
                ,url: Doodle.config.connectorUrl
                ,baseParams: {
                    action: 'mgr/doodle/update'
                }
                ,autoHeight: false
                ,height: Ext.getBody().getViewSize().height*.85
                ,autoScroll: true
                ,fields: [{
                    xtype: 'hidden'
                    ,name: 'id'
                },{
                    xtype: 'textfield'
                    ,fieldLabel: 'Doodle Name'
                    ,name: 'DoodleName'
                    ,anchor: '100%'
                },{
                    xtype: 'doodle-grid-doodleoptions'
                    ,fieldLabel: 'Doodle Options'
                }]
            });
            Doodle.window.UpdateDoodleList.superclass.constructor.call(this,config);
        };
        Ext.extend(Doodle.window.UpdateDoodle,MODx.Window);
        Ext.reg('doodle-window-doodlelist',Doodle.window.UpdateDoodle);
        
        Doodle.grid.DoodleOptions = function(config) {
            config = config || {};
            Ext.applyIf(config,{
                id: 'doodle-grid-doodleoptions'
                ,url: Doodle.config.connectorUrl
                ,baseParams: {
                    action: 'mgr/doodles/getoptionlist'
                }
                ,viewConfig: {
                    forceFit: true,
                    enableRowBody: true
                }
                ,fields: ['id','DoodleOption','DoodleOptionPrice']
                ,paging: false
                ,showPerPage: false
                ,remoteSort: true
                ,columns: [{
                    header: 'Doodle Option Name'
                    ,dataIndex: 'DoodleOption'
                    ,sortable: true
                    ,width: 20
                },{
                    header: 'Doodle Option Price'
                    ,dataIndex: 'DoodleOptionPrice'
                    ,sortable: true
                    ,width: 20
                }]
            });
            Doodle.grid.DoodleOptions.superclass.constructor.call(this,config);
        };
        Ext.extend(Doodle.grid.DoodleOptions,MODx.grid.Grid);
        Ext.reg('doodle-grid-doodleoptions',Doodle.grid.DoodleOptions);
        


        When I defined the grid that will be placed in the modal window, I only defined the action baseParams. In the code that defines the modal window, I define xtype: 'doodle-grid-doodleoptions' and the label within the fields. Finally, in the main page grid, I modified the function that loads and display's the modal window by placing:
                    var optionsgrid = Ext.getCmp('doodle-grid-doodleoptions');
                    optionsgrid.store.load({params:{doodle_id: this.menu.record.id || 0}});
        

        This will pass the id of the doodle to the window grid, which will then run the action to pull the options from the processor.

        Hope this helps anyone else needing to do something similar.
          • 14951
          • 151 Posts
          Quote from: insomnix at Jul 21, 2012, 03:04 AM
          Hope this helps anyone else needing to do something similar.

          Thank you so much for posting back on this! I was having a very similar issue and your post helped me solve the issue!
            • 37286
            • 160 Posts
            It's nice to hear back from someone I was able to help out, even if it's just a point in the right direction. Thanks.
              • 11742 ☆ A M B ☆
              • 53 Posts
              Thanks insomnix, this is exactly what I looked for!

                Freelance Web Developer who likes MODX, PHP, jQuery, ExtJS, SASS and other cool web things. Currenty doing great stuff at COEX CZ.

                GitHub: https://github.com/hansek
                Follow me: https://twitter.com/jantezner
                Or follow us: https://twitter.com/coexcz

                http://www.modx.cz || http://www.coex.cz
                • 14951
                • 151 Posts
                Did you (or anyone) happen to have trouble with the grid pagination after using this method?

                This works great for loading the grid in the window the first time, but if you hit the "refresh" button or use any of the pagination features things go awry.

                Looking at the POST in firebug, it appears that it leaves out the original parameters and reverts back to the standard parameters only (action,start,limit) on the POST that gets fired when you use the pagination links.

                I'm not sure if it's because I'm using this approach to populate my grid or if it's something else?

                Interestingly enough, programmaticly refreshing the grid (i.e. this.refresh) seems to work okay.. It's only an issue with pagination.

                Thanks for any insight!
                  • 37286
                  • 160 Posts
                  I have had problems with the pagination and when you select refresh, sometimes it doesn't grab changed data from the database, but only looks like it does. Most of the time I use this I'm only displaying a few items and moving on, but recently I've started to use this with more advanced displays with more data. I'm still trying to work this out, but have been on other projects. If you happen to find a solution, please share.
                    • 4172
                    • 5,888 Posts
                    if you want to do that the easy way, with MIGXdb you would just add a MIGXdb-TV-type into your formtab.
                    This can also be multiple grids.
                      -------------------------------

                      you can buy me a beer, if you like MIGX

                      http://webcmsolutions.de/migx.html

                      Thanks!
                      • 14951
                      • 151 Posts
                      @insomnix

                      I think I have a "partial" solution.. Basically, we have to override the "change" listener that the grid pagination uses.

                      First step is to update your store.load call with the start and limit parameters (setting the limit to whatever your pageSize is:
                      optionsgrid.store.load({params:{doodle_id: this.menu.record.id || 0 ,start: 0 ,limit: 5}});

                      This will fix the issues with pagination on initial load.

                      Then, on the grid, you need to overide the "change" listener with something like this:
                      ,listeners: {
                      'change': {fn:function(tf,nv,ov) {
                      if (Ext.isEmpty(nv)) return false;
                      nv = parseInt(nv);
                      this.getBottomToolbar().pageSize = nv;
                      this.store.load({params:{
                      start:0
                      ,limit: nv
                      ,doodle_id: doodid //variable holding your doodle id
                      }});
                      },scope:this}
                      }


                      EDIT: I lied... Spoke too soon.. that listener is on the actual text field.. not the grid it self.


                      The problem I'm having now is that I'm once again stuck trying to figure out how to dynamically pass that value into the change listener.

                      Anyhow...will keep working on it. Hopefully that will put you on the right track as well.

                      @bruno17 - Thanks, I just haven't taken the time to learn MIGXdb yet so it would probably take me twice as long to figure everything out wink

                      Thanks! [ed. note: jaredloman last edited this post 13 years, 5 months ago.]