We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 44195
    • 293 Posts
    Hi!

    I'm attempting to learn modext/extjs so hopefully someone has some patience wink
    I have a modext grid and I would like to load a new grid when a row is clicked. (Passing the row id of course)

    So far I've attached a rowclick listener and attempted to added a changePanel() function but I'm not clear on how to call the panel the grid is a child of. Can I call it via its ID? or xtype?

    ,listeners : {
        'rowclick': function(grid, index, rec){
            
            this.changePanel();
    
        }
    }
    

    Ext.extend(ExampleProject.grid.Competitions,MODx.grid.Grid,{
        changePanel: function() {
            // Somehow call a function on the container of this grid, remove the grid and load a new one.
        }
    });
    



    Thanks in advance.
    Muzz [ed. note: muzzstick last edited this post 12 years, 7 months ago.]
      I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
      Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
      • 44195
      • 293 Posts
      Ok, I've progressed a bit. For anyone who may be trying to figure the same thing out:

      My new changePanel() function on the grid:
      ,changePanel: function(grid, id) {
          Ext.getCmp('home-panel').replaceGrid(grid, id);
      }
      

      I call it with:
      ,listeners : {
          'rowclick': function(grid, index, rec){
              if (grid.getSelectionModel().hasSelection()) {
                  var row = grid.getSelectionModel().getSelections()[0];
                  var id = row.get('id');
              }
              this.changePanel(grid, id);
          }
      }
      


      I extended the home panel which the grid is a child of and added a replaceGrid() function.
      This is where I'm now getting a bit stuck.
      Ext.extend(ExampleProject.panel.Home,MODx.Panel,{
          replaceGrid: function(grid, id) {
              var tabs = Ext.getCmp('main-tabs');
              var tab = tabs.getActiveTab();
              tab.remove('exampleproject-grid-competitions');
      
              var artworkGrid = new Ext.getCmp('exampleproject-grid-artworks');
              tab.add(artworkGrid);
              tab.doLayout();
          }
      });
      

      The original grid is removed from the panel no problem but the new one is not being displayed.
      For simplicity, the "exampleproject-grid-artworks" grid is exactly the same as the original grid besides the naming and the database table it points to.

      I have a feeling I'm not instantiating the new grid correctly. Any ideas? smiley
        I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
        Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
        • 44195
        • 293 Posts
        Well I think I can tentatively say I've worked it out...

        Ext.extend(ExampleProject.panel.Home,MODx.Panel,{
            replaceGrid: function(grid, id) {
                var tabs = Ext.getCmp('main-tabs');
                var tab = tabs.getActiveTab();
                tab.remove('exampleproject-grid-competitions');
         
                var artworkGrid = new ExampleProject.grid.Artworks; // This is the line that was changed
                tab.add(artworkGrid);
                tab.doLayout();
            }
        });
        


          I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
          Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Good luck! That gave me a headache just thinking about it!
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 44195
            • 293 Posts
            I've learned since then that apparently it's better practice to use Ext.create() rather than the 'new' keyword.
              I'm lead developer at Digital Penguin Creative Studio in Hong Kong. https://www.digitalpenguin.hk
              Check out the MODX tutorial series on my blog at https://www.hkwebdeveloper.com