Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: How to show hyper link as grid cell content and make it can listen to click event?

  1. #1

    Default How to show hyper link as grid cell content and make it can listen to click event?

    As the title.

  2. #2

    Default

    Quote Originally Posted by taocore View Post
    As the title.
    you can use a cell renderer (specified in the cm) and return the <a href="...>
    e.g.
    Code:
    function emailRenderer(val) {
        if (val != null) {
            return '<a href=\'mailto:' + val + ';\'>' + val + '</a>';
        }
        return val;
    }
    then in your cm

    Code:
    {header: "Email", width: 100, dataIndex: 'email',renderer:emailRenderer}

  3. #3

    Default

    I know how to render a cell. But I want to do some complex things not just mailto or other simple url link when the hyper link was clicked. Should I use the renderer like this:
    Code:
    return "<a href='javascript:void(0)' onclick='javascriptFunction'> " + model.get("name") + "</a>";
    and invoke a javascript function.

    Any pure java solution? I am not familiar with javascript.

  4. #4
    Ext GWT Premium Member gslender's Avatar
    Join Date
    Mar 2008
    Location
    Brisbane, Australia
    Posts
    1,572

    Default

    it really depends on what you are trying to do... if need something to click on, why not just listen to the cellselection events and work from that? there is then no need to render html that calls javascript.

    btw - grid can only render html string so whilst you can put in javascript, its going to be immensely complex to plain Javascript->JSNI from GWT to work.

  5. #5

    Post The same problem - can't handle click event on Image in grid cell

    The problem is the same : click listener is not fired when anchor (and inner image) is inserted in grid cell using renderer
    i'e tried :

    ex1:

    Code:
    HTML h = new HTML("<a .. > ... </a>");
    h.addClickListener(new ClickListener() {
    
      public void onClick(Widget sender) {
            // is not fired :(
      }
    });
    
    // during rendering
    return h.getHTML();
    ex2:

    Code:
    Hyperlink h = new Hyperlink();
    h.setText("link");
    h.addClickListener( /*  the same */ );
    
    // during rendering
    return h.getHTML();
    ex3:

    Code:
    Widget w = new Widget() {
                    public void onBrowserEvent(Event event) {
                        // is not fired
                      }
                };
    w.sinkEvents(Events.OnClick);
    DOM.setEventListener(image.getElement(), w);
    What should i do to handle it?

  6. #6
    Ext User
    Join Date
    Oct 2008
    Location
    Atlanta ,GA
    Posts
    239

    Default

    Something similar, HTML image click in a grid.
    http://ravikolli.blogspot.com/2009/0...nt-in-gxt.html

  7. #7

    Default

    Quote Originally Posted by kolli View Post
    Something similar, HTML image click in a grid.
    http://ravikolli.blogspot.com/2009/0...nt-in-gxt.html
    Hmm, cell click is not the same as just element in it.
    It is needed to define what cell and element in int was clicked exactly (using target or smth)

  8. #8
    Ext User
    Join Date
    Oct 2008
    Location
    Atlanta ,GA
    Posts
    239

    Default

    yap that is what u should be doing..

  9. #9

    Default

    Here is my solution to this issue :


    Code:
    // you could design column1 with a custom renderer, any hyper link or image
    [...]
    
    final Grid<MyItem> grid = new Grid<MyItem>(store, cm);
    final int indexCol = cm.findColumnIndex("column1");
    
    grid.addListener(Events.CellClick, new Listener<BaseEvent>() {
    	public void handleEvent(BaseEvent be) {
    		GridEvent ge = (GridEvent) be;
    		if (ge.colIndex == indexCol) {
    			MyItem i = grid.getSelectionModel().getSelectedItem();
    			
    			// Do stuff with My item, remove it ...
    			store.remove(i);
    		}
    	}
    });

  10. #10

    Default Email Window Template

    I have a hyperlink in a grid column. when ever i am going to clink that email link that time a new email window open with that mail id in to field? Request to please help me.

Page 1 of 2 12 LastLast

Posting Permissions

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