mahesh00400
mahesh00400

Reputation: 31

How to add data- attribute to extjs button

I want to add a data- attribute to extjs button at time of creation.I used the setAttributes method but i dont want to use setAttributes method.data- attribute should be added just like other config options.

Upvotes: 0

Views: 1928

Answers (3)

mahesh00400
mahesh00400

Reputation: 31

Add following code snippet in your button listeners

afterrender:function(button){
         button.getEl().set({
         "data-id": "some text"
         });  
    }

Upvotes: 1

CD..
CD..

Reputation: 74176

You can use the autoEl property for that, like:

{
  xtype: 'button',
  text: 'Button',
  autoEl: {
    'data-attribute': 'foobar'
  }
}

Working example: https://fiddle.sencha.com/#fiddle/1d0d

Upvotes: 4

Fresh Prince
Fresh Prince

Reputation: 11

You can add your own data attributes like this:

var button = new Ext.button.Button({
id: 'mybutton',
text: 'Click me',
'data-attribute': data,
handler: function() {
    alert('You clicked the button!');
}
});

Upvotes: -1

Related Questions