View Full Version : ExtJS 4.x Button example

26 Jul 2012, 1:08 AM
Hello! I am a novice ExtJS 4.x developer. I need a good example button action code. My task is simple calculator: press the digit button and see the digit in the label.:-/

26 Jul 2012, 1:15 AM
you can attach a handler to each button either during creation or add a listener for the click event after creation:

Ext.create (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext-method-create)('Ext.Button (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext.button.Button)', {
text: '1',
renderTo: Ext.getBody (http://docs.sencha.com/ext-js/4-0/#%21/api/Ext-method-getBody)(), // or add it to a form/window/panel etc.
handler: function() {
Ext.getCmp('your_displayfield').setValue(1); // set value 1 for e.g. in the display field

If you want to append values to an already existing value in the field, then first get value, append the value of this button and then setValue().

27 Jul 2012, 12:27 AM
It was very useful for me.:)