Reputation: 31
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
Reputation: 31
Add following code snippet in your button listeners
afterrender:function(button){
button.getEl().set({
"data-id": "some text"
});
}
Upvotes: 1
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
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