Reputation: 11128
I want to add Canvas
element into ExtJS Container
element. But it accepts only Ext.Component
, not any dom element.
Canvas create code:
canvas = document.createElement('canvas');
How to insert it into container, or I need to use another ext component? I need to have some resize logic for component, container have it.
Upvotes: 2
Views: 18687
Reputation: 30082
The best way to do this is to create a component where the element is the canvas. This way, you get all the built in layout stuff for "free" basically.
new Ext.container.Container({
width: 400,
height: 400,
layout: 'fit',
items: {
xtype: 'component',
autoEl: {
tag: 'canvas'
}
}
});
Upvotes: 5
Reputation: 12447
DomHelper is useful here, e.g:
Ext.DomHelper.append(your_container.body, { tag: 'canvas' })
Upvotes: 4
Reputation: 12961
you can add a panel to your container as your canvas container like:
Ext.getCmp('yourContainer').add(Ext.create('Ext.Panel', {
html: '<div id="canvasContainer"></div>'
}));
then add your stuff to it:
var canvas = document.createElement('canvas');
$("#canvasContainer").appendChild(canvas);
or you can easily add your html element like:
Ext.getCmp('yourContainer').add(Ext.create('Ext.Panel', {
html: '<canvas></canvas>'
}));
Upvotes: 1
Reputation: 37506
You can use the Container's update
method to put in raw HTML. Panel is a better object to use here because you can use its html
constructor config parameter to just dump whatever HTML you want upon creation. Ex:
var panel = {
xtype: 'panel',
html: ['<div>',
'<p>Hi!</p>',
'</div>'].join("\n");
}
Upvotes: 4