nkuhta
nkuhta

Reputation: 11128

How to add simple dom-element into ExtJS container?

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

Answers (4)

Evan Trimboli
Evan Trimboli

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

Rob Agar
Rob Agar

Reputation: 12447

DomHelper is useful here, e.g:

Ext.DomHelper.append(your_container.body, { tag: 'canvas' })

Upvotes: 4

Mehran Hatami
Mehran Hatami

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

Mike Thomsen
Mike Thomsen

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

Related Questions