Results 1 to 3 of 3

Thread: Listener on a hyperlink

  1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    39
    Vote Rating
    0
      0  

    Default Answered: Listener on a hyperlink

    Hey everybody,

    I'm creating something like a forum. The list of threads is in a grid. I want the user to be able to click on the title (not the cell the title is in, just the title) to open up the list of responses for that thread. The list of responses are on another card (the panel is in card layout).

    So it's similar to a hyperlink, and if there is a way to attach listeners to those that'd be great. But if you know another way, that's fine too.

    Thanks for your help

  2. You can use a column renderer and return a wrapped text for the title:

    Code:
    renderer: function(title) {
        return '<span class="thread-title">' + title + '</span>';
    }
    Now, you can add a listener to the grid for the click event on that <span> tag. There are two ways to do this:

    Code:
    Ext.create('Ext.grid.Panel', {
        //....
    
        listeners : {
            el : {
                delegate : 'span.thread-title',
                click    : function(e) {
                    var view = grid.getView(),
                        el   = e.getTarget('tr', null, true),
                        rec  = view.getRecord(el);
                }
            }
        }
    });
    or

    Code:
    grid.mon(grid.el, {
        delegate : 'span.thread-title',
        click    : function(e) {
            var view = grid.getView(),
                el   = e.getTarget('tr', null, true),
                rec  = view.getRecord(el);
        }
    });
    Now, only when you click on the <span class="thread-title"> will this fire and you have the record in the rec variable.

    To finish it off, I would style the <span> a little... I would color it and add a cursor:

    Code:
    span.thread-title {
        color  : #00f;
        cursor : pointer;
    }

  3. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,062
    Answers
    3976
    Vote Rating
    1390
      0  

    Default

    You can use a column renderer and return a wrapped text for the title:

    Code:
    renderer: function(title) {
        return '<span class="thread-title">' + title + '</span>';
    }
    Now, you can add a listener to the grid for the click event on that <span> tag. There are two ways to do this:

    Code:
    Ext.create('Ext.grid.Panel', {
        //....
    
        listeners : {
            el : {
                delegate : 'span.thread-title',
                click    : function(e) {
                    var view = grid.getView(),
                        el   = e.getTarget('tr', null, true),
                        rec  = view.getRecord(el);
                }
            }
        }
    });
    or

    Code:
    grid.mon(grid.el, {
        delegate : 'span.thread-title',
        click    : function(e) {
            var view = grid.getView(),
                el   = e.getTarget('tr', null, true),
                rec  = view.getRecord(el);
        }
    });
    Now, only when you click on the <span class="thread-title"> will this fire and you have the record in the rec variable.

    To finish it off, I would style the <span> a little... I would color it and add a cursor:

    Code:
    span.thread-title {
        color  : #00f;
        cursor : pointer;
    }
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha User
    Join Date
    May 2011
    Posts
    39
    Vote Rating
    0
      0  

    Default

    That worked perfectly! Thanks a lot.

Posting Permissions

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