Results 1 to 2 of 2

Thread: Reusable tbar + rowCtx for Grids

  1. #1
    Sencha User
    Join Date
    Jun 2010
    Posts
    33

    Default Reusable tbar + rowCtx for Grids

    I am trying to make standardized reusable menu's for certain type of grids (IE a grid with usernames or a grid with adresses). I want to have the same buttons in both the topbar and the rowctxmenu.

    Each button will have to find the selected row's ID value, so I used:
    PHP Code:
    this.findParentByType('grid').getSelectionModel().getSelected().get("ID"); 
    This works fine for the topbar items, but not when I use them in a rowCtxMenu.

    PHP Code:
    var buttons = [ 
    {
     
    text'Show details',
     
    handler: function(){
      
    showDetails(this.findParentByType('grid').getSelectionModel().getSelected().get("Id"));
     }
    },{
     
    text'Delete',
     
    handler: function(){
      
    deleteRow(this.findParentByType('grid').getSelectionModel().getSelected().get("Id"));
     }
    }
    ];

    var 
    grid = new Ext.grid.GridPanel({
        
    sm: new Ext.grid.RowSelectionModel({
            
    singleSelecttrue
        
    }),
        
    rowCtxMenu: new Ext.menu.Menu({
            
    itemsbuttons
        
    }),
        
    tbar: new Ext.Toolbar({
           
    items buttons
        
    })
    });

    autoLijstGrid.on('rowcontextmenu',function(gridrowIdxevtObj){
        
    evtObj.stopEvent();
        
    grid.getSelectionModel().selectRow(rowIdx);
        
    grid.rowCtxMenu.showAt(evtObj.getXY());
    }); 
    When I click on a RowCtxMenuItem, I get
    PHP Code:
    this.findParentByType("grid"is null 
    In the tbar it works just fine.

  2. #2
    Sencha User
    Join Date
    Jun 2010
    Posts
    33

    Default

    Now that I think of it, the rowCtxMenu is rendered using showAt(), so it probably doesn't have a parent at all.

    I could set a variable in the 'rowcontextmenu' event hander of the grid, that points to the grid.

    PHP Code:
    grid.on('rowcontextmenu',function(gridrowIdxevtObj){
        
    evtObj.stopEvent();
        
    grid.getSelectionModel().selectRow(rowIdx);
        
    gridname grid;
        
    grid.rowCtxMenu.showAt(evtObj.getXY());
    }); 
    And for the button handler:
    PHP Code:
    handler: function(){
     
    thisgrid = if(this.findParentByType('grid'))? this.findParentByType('grid') : gridname;
     
    showDetails(thisgrid.getSelectionModel().getSelected().get("Id"));

    But there must be a better solution!

Similar Threads

  1. GridPanel with tbar - tbar has display issues
    By froggman2k in forum Ext 3.x: Help & Discussion
    Replies: 4
    Last Post: 16 Feb 2010, 2:44 PM
  2. tabs tbar dissapears when tbar button clicked
    By robert_speer in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 11 Aug 2008, 7:47 AM
  3. Button in grids tbar to bring up another grid?
    By se7en.hu in forum Ext 2.x: Help & Discussion
    Replies: 9
    Last Post: 27 Jun 2008, 7:31 PM
  4. Replies: 2
    Last Post: 18 Apr 2008, 1:03 AM
  5. My reusable component...
    By Rocco in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 18 Jan 2008, 8:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •