1
votes

How to use hbox in extJS dataview.

I am using dataview in my app. Here is the code and using this link. dataview link

Ext.define('Image', {
    extend: 'Ext.data.Model',
    fields: [
        { name:'src', type:'string' },
        { name:'caption', type:'string' }
    ]
});

Ext.create('Ext.data.Store', {
    id:'imagesStore',
    model: 'Image',
    data: [
        { src:'http://www.sencha.com/img/20110215-feat-drawing.png', caption:'Drawing & Charts' },
        { src:'http://www.sencha.com/img/20110215-feat-data.png', caption:'Advanced Data' },
        { src:'http://www.sencha.com/img/20110215-feat-html5.png', caption:'Overhauled Theme' },
        { src:'http://www.sencha.com/img/20110215-feat-perf.png', caption:'Performance Tuned' }
    ]
});

var imageTpl = new Ext.XTemplate(
    '<tpl for=".">',
        '<div style="margin-bottom: 10px;" class="thumb-wrap">',
          '<img src="{src}" />',
          '<br/><span>{caption}</span>',
        '</div>',
    '</tpl>'
);

Ext.create('Ext.view.View', {
    store: Ext.data.StoreManager.lookup('imagesStore'),
    tpl: imageTpl,
    itemSelector: 'div.thumb-wrap',
    emptyText: 'No images available',
    renderTo: Ext.getBody()
});

Now in this code elements are geting vertically. One below to another. I want elent should get placed 2 in one row. for that I am using this but no luck .

layout: {
                type: 'table',
                columns: 2
            },
            

Can anyone help me to solve this

1
Did you see this Fiddle. Typically what you do give each item a width of 50% and add a flex layout to it. - Dinkheller

1 Answers

1
votes

There is no layout property in 'Ext.view.View'. You can use css grid for this purpose:

Ext.define('Image', {
    extend: 'Ext.data.Model',
    fields: [
        { name:'src', type:'string' },
        { name:'caption', type:'string' }
    ]
});

Ext.create('Ext.data.Store', {
    id:'imagesStore',
    model: 'Image',
    data: [
        { src:'https://picsum.photos/id/0/200/300', caption:'Drawing & Charts' },
        { src:'https://picsum.photos/id/1/200/300', caption:'Drawing & Charts' },
        { src:'https://picsum.photos/id/2/200/300', caption:'Advanced Data' },
        { src:'https://picsum.photos/id/3/200/300', caption:'Overhauled Theme' },
        { src:'https://picsum.photos/id/4/200/300', caption:'Performance Tuned' }
    ]
});

var imageTpl = new Ext.XTemplate(
    '<div style="display: grid; grid-template-columns: 200px 200px;">', // wrapper div with grid layout
        '<tpl for=".">',
            '<div style="margin-bottom: 10px;" class="thumb-wrap">',
              '<img src="{src}" style="max-width: 50%;"/>',
              '<br/><span>{caption}</span>',
            '</div>',
        '</tpl>',
    '</div>'
);

Ext.create('Ext.view.View', {
    store: Ext.data.StoreManager.lookup('imagesStore'),
    tpl: imageTpl,
    itemSelector: 'div.thumb-wrap',
    emptyText: 'No images available',
    renderTo: Ext.getBody()
});