1

I am dynamically adding panels to my container, once all the panels are added i want to have click event for the panels and listen to the event in one of the controller with the panel clicked being the argument.

I have the following code for adding the click event.

 '#productListPanel': {              
          afterrender: this.onProductPanelAfterRender,
},


 onProductPanelAfterRender: function(panel) {
    panel.mon(panel.el, 'click', this.onProductPanelClick);
},

 onProductPanelClick: function(a,b) {
    console.log("a");
    console.log(a);
    console.log("b");
    console.log(b);
},

It works fine and adds the click event, but i am not able to determine which panel is being clicked.

can somebody please help me out.

Thanks

1
  • From 14 Question you had, you accepted only 2? Let's be serious: are you really expecting answers?
    – V G
    Mar 18, 2014 at 9:59

2 Answers 2

4

When you add dynamically a panel to your container, you can add a listener into your panel definition :

listeners: {
   'render': function(panel) {
       panel.body.on('click', function() {
           nameOfYourApp.app.fireEvent('ClickPanel',panel);
       });
    }
}

Fire an event when the panel is clicked and listen this event into your controller.

You can add this code into the init function of your controller :

    this.application.addListener({
        'ClickPanel':this.clickPanel
    });

and add the function "clickPanel" into your controller :

clickPanel:function(panel){
    // Your code
}

hope this can be helpful for your problem!

1
  • 1
    Thanks man!!! it works....rather than adding the listener into panel definition i can add it in controller, just to keep the view and controller separate. Mar 19, 2014 at 4:34
0

If you wanted to do it after the panel is rendered you can use the following. This assume myPanel is a reference to your panel.

myPanel.getEl().on('click',
    function(){
        alert('Panel Clicked');
    }
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.