1. #1
    Ext User
    Join Date
    Oct 2008
    Posts
    35
    Vote Rating
    0
    sbarkdull is on a distinguished road

      0  

    Default Which grid row is clicked when opening context menu?

    Which grid row is clicked when opening context menu?


    I am trying to figure out which row in the Grid the user right-clicked in when opening the context menu in a grid.

    I am adding a SelectionListener to a MenuItem, which is added to a Menu, which is set as the Grid's context menu (see code snippet below). Do I need to do something like detect a right click in the grid, save which row was clicked in, and make that row number available to the componentSelected() method in the listener? Is there a way to get the row index information from the MenuEvent in the listener?

    Menu m = new Menu();
    Item item = new MenuItem( "Respond", "reply-menu-item", new SelectionListener<MenuEvent>() {

    @Override
    public void componentSelected(MenuEvent ce) {
    int rowIndex = do something here to get the row index
    handleReplyRequest( rowIndex );
    }

    });
    m.add( item );
    grid.setContextMenu( m );

  2. #2
    Ext User
    Join Date
    Jan 2008
    Posts
    1
    Vote Rating
    0
    knockatthedoor is on a distinguished road

      0  

    Smile This is how i do it on my app?

    This is how i do it on my app?


    Sorry, didnt see your post was in the GXT section im working on EXTJS
    Last edited by knockatthedoor; 15 Dec 2008 at 10:59 AM. Reason: Me being a plonker

  3. #3
    Ext User karacutey's Avatar
    Join Date
    Nov 2008
    Posts
    46
    Vote Rating
    0
    karacutey is on a distinguished road

      0  

    Default


    grid.getSelectionModel().getSelectedItem().get("dataModelPropertyName")

    where grid is your grid component, you can access that via static reference or via the selection event

    for the selection event it would be something like

    Code:
    public void handleEvent(SelectionEvent se) {
    ModelData rowData = (ModelData) se.selection.get(0);
    }

  4. #4
    Ext User karacutey's Avatar
    Join Date
    Nov 2008
    Posts
    46
    Vote Rating
    0
    karacutey is on a distinguished road

      0  

    Default


    okay this is tested and works. only right clicks on the row.

    this extends a content panel IE XMLGridPanel Class

    Code:
    package com.yourorg.yourproject
    
    import com.allen_sauer.gwt.log.client.Log;
    import com.extjs.gxt.ui.client.Events;
    import com.extjs.gxt.ui.client.Style.SelectionMode;
    import com.extjs.gxt.ui.client.data.ModelType;
    import com.extjs.gxt.ui.client.event.GridEvent;
    import com.extjs.gxt.ui.client.event.Listener;
    import com.extjs.gxt.ui.client.widget.TabItem;
    import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
    import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
    import com.extjs.gxt.ui.client.widget.grid.Grid;
    import com.extjs.gxt.ui.client.widget.layout.FitLayout;
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     *
     * @author Kara
     */
    public class ViewCompanyConfsSchedTabPanel extends TabItem {
    
        public ViewCompanyConfsSchedTabPanel(String id, String companyId, String name) {
            
            //do some queries or something
    
            XMLGridPanel gp = new XMLGridPanel();
            gp.setRequestUrl(url);
    
            ColumnConfig columnConfigNameFirst = new ColumnConfig("nameFirst", "First Name", 100);
            ColumnConfig columnConfigNameLast = new ColumnConfig("nameLast", "Last Name", 100);
    
            List<ColumnConfig> config = new ArrayList<ColumnConfig>();
    
            config.add(columnConfigNameFirst);
            config.add(columnConfigNameLast);
    
            ModelType mt = new ModelType();
            mt.root = "...";
    
            //define the rest of your model here
    
            final ColumnModel cm = new ColumnModel(config);
            gp.setColumnModel(cm);
            gp.setModelType(mt);
    
            gp.show();
            gp.layout();
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    //SETS YOUR CONTEXT MENU
    //
            gp.getGrid().setContextMenu(new ConfSchedContextMenu());
    //
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    
            this.setLayout(new FitLayout());
    
            this.add(gp);
            this.layout();
    
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    //SETS YOUR CONTEXT MENU LISTENERS
    //
            setGridListeners(gp);
    //
    //////////////////////////////////////////////////////////////////////////////////////////////////////////
    
            //Perform some load method or init on your Grid to Display load it
        }
    
        private void setGridListeners(XMLGridPanel xmlGridPanel) {
            final Grid grid = (Grid) xmlGridPanel.getItemByItemId("xmlGridPanel");
            grid.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    
            grid.addListener(Events.ContextMenu, new Listener<GridEvent>() {
    
                public void handleEvent(GridEvent comeOn) {
    
                    String cI = comeOn.event.getTarget().getClassName();
                    String mS = "-hd-inner";
    
                    comeOn.doit = ifItIsAGridRow(comeOn);
    
                    Log.info("[CONTEXT CALL] " + comeOn.doit);
                }
            });
        }
    
        private boolean ifItIsAGridRow(GridEvent ge) {
            String cI = ge.event.getTarget().getClassName();
            String mS = "-hd-inner";
    
            if (cI.indexOf(mS) == -1) {
                return true;
            } else {
                return false;
            }
        }
    }

  5. #5
    Ext User
    Join Date
    Sep 2008
    Posts
    7
    Vote Rating
    0
    ErikL is on a distinguished road

      0  

    Thumbs up


    Thanks Kara. Excellent post, helped me a lot when implementing context menu for Grid cells, i.e:

    Code:
    grid.addListener(Events.ContextMenu, new Listener<GridEvent>() {
    
                    public void handleEvent(GridEvent be) {
    
                        ((CellSelectionModel<BaseModel>) be.grid.getSelectionModel())
                                    .selectCell(be.rowIndex, be.colIndex);
                    }
                     
    });

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..."