'programmatically click a button in Extjs

I use the MVC-architecture in Extjs application. I have a simply button, it looks like a:

{
  xtype: 'button',
  id: 'searchButton',
  margin: '5 0',
  text: 'Search'
}

And how I can press it button programmatically from this view?



Solution 1:[1]

I think imitate button-click from view it is a not good solution. If you use a MVC-architecture you may do it from Controller. And you may fire events, because your solution is bad way. But if you still want do it, this code I think will be helpful for you:

Ext.get('searchButton').dom.click();

And please read this article in official site EXTjs MVC-architecture

Solution 2:[2]

I made the same thing using this:

 var ele = Ext.getCmp("searchButton");
 ele.fireEvent('click');

Solution 3:[3]

For ExtJs 3.0 / 3.4 you can use

Ext.getCmp("searchButton").el.dom.click()

.el.dom return the actual HTML object for every ExtJs object... so once you reach el.dom now you are doing normal JavaScript... this applies nearly to all ExtJs elements.

Solution 4:[4]

in controller get the reference for the element just and call click() :

var me = this;

var refs = me.getReferences();
var save = refs.save_button;
save.click();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user
Solution 2 Alejandro Luna
Solution 3
Solution 4 Mohammed_Moulla