当我隐藏内部有图像的列时,网格行不会改变高度

发布于 2024-11-30 17:18:40 字数 2152 浏览 1 评论 0原文

扩展JS 4.0.2。我有网格,每行都有显示图像的列(100x100)。当网格渲染时,每行的高度约为 120px。当我隐藏带有图像的列时,我想更改行的高度,以便它们的高度像一个文本行。怎么做呢?我查看了 http: //docs.sencha.com/ext-js/4-0/#/api/Ext.grid.column.Column-cfg-hideMode 但它没有达到我想要的效果。

已更新 代码:

Ext.onReady(function() {


var myData = [
    ['3m Co','logo-small.png'],
    ['Alcoa Inc','logo-small.png'],
    ['Altria Group Inc','logo-small.png']
];


// create the data store
var store = Ext.create('Ext.data.ArrayStore', {
    fields: [
       {name: 'company'},
       'url'
    ],
    data: myData
});

// create the Grid
var grid = Ext.create('Ext.grid.Panel', {
    store: store,
    stateful: true,
    stateId: 'stateGrid',
    columns: [
        {
            text     : 'Company',
            flex     : 1,
            dataIndex: 'company'
        } ,
        {
            text     : 'Image',
            width: 200,
            hidden: true,
            hideMode: 'display',
            renderer : function(value){
                return '<img src="'+value+'">';
            },
            dataIndex: 'url'
        }

    ],
    height: 350,
    width: 600,
    title: 'Array Grid',
    renderTo: 'grid-example',
    viewConfig: {
        stripeRows: true
    }
}); });

当隐藏列时,每行仍然有足够的高度来显示图像,我希望它们具有像没有图像列一样的高度

Ext.onReady(function() {
 var myData = [
    ['3m Co','logo-small.png'],
    ['Alcoa Inc','logo-small.png'],
    ['Altria Group Inc','logo-small.png']
];


// create the data store
var store = Ext.create('Ext.data.ArrayStore', {
    fields: [
       {name: 'company'},
       'url'
    ],
    data: myData
});

// create the Grid
var grid = Ext.create('Ext.grid.Panel', {
    store: store,
    stateful: true,
    stateId: 'stateGrid',
    columns: [
        {
            text     : 'Company',
            flex     : 1,
            dataIndex: 'company'
        }  

    ],
    height: 350,
    width: 600,
    title: 'Array Grid',
    renderTo: 'grid-example',
    viewConfig: {
        stripeRows: true
    }
}); }); 

Ext JS 4.0.2. I have grid, and every row has column which display image (100x100). When grid is rendered every row has height about 120px. When i hide column with image inside i want to change height of rows so they have height like a one text line. How to do it? I looked at http://docs.sencha.com/ext-js/4-0/#/api/Ext.grid.column.Column-cfg-hideMode but it doesn't do what i want.

updated
code:

Ext.onReady(function() {


var myData = [
    ['3m Co','logo-small.png'],
    ['Alcoa Inc','logo-small.png'],
    ['Altria Group Inc','logo-small.png']
];


// create the data store
var store = Ext.create('Ext.data.ArrayStore', {
    fields: [
       {name: 'company'},
       'url'
    ],
    data: myData
});

// create the Grid
var grid = Ext.create('Ext.grid.Panel', {
    store: store,
    stateful: true,
    stateId: 'stateGrid',
    columns: [
        {
            text     : 'Company',
            flex     : 1,
            dataIndex: 'company'
        } ,
        {
            text     : 'Image',
            width: 200,
            hidden: true,
            hideMode: 'display',
            renderer : function(value){
                return '<img src="'+value+'">';
            },
            dataIndex: 'url'
        }

    ],
    height: 350,
    width: 600,
    title: 'Array Grid',
    renderTo: 'grid-example',
    viewConfig: {
        stripeRows: true
    }
}); });

when column is hidden each row has still enough height to display image, i want them to have height like there is no image column

Ext.onReady(function() {
 var myData = [
    ['3m Co','logo-small.png'],
    ['Alcoa Inc','logo-small.png'],
    ['Altria Group Inc','logo-small.png']
];


// create the data store
var store = Ext.create('Ext.data.ArrayStore', {
    fields: [
       {name: 'company'},
       'url'
    ],
    data: myData
});

// create the Grid
var grid = Ext.create('Ext.grid.Panel', {
    store: store,
    stateful: true,
    stateId: 'stateGrid',
    columns: [
        {
            text     : 'Company',
            flex     : 1,
            dataIndex: 'company'
        }  

    ],
    height: 350,
    width: 600,
    title: 'Array Grid',
    renderTo: 'grid-example',
    viewConfig: {
        stripeRows: true
    }
}); }); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苄①跕圉湢 2024-12-07 17:18:40

这个问题相当老了,但我认为我的回答可能会对某人有所帮助。

Ext.onReady(function() {
var myData = [
    {company: '3m Co',url: 'logo-small.png'},
    {company: 'Alcoa Inc',url: 'logo-small.png'},
    {company: 'Altria Group Inc',url: 'logo-small.png'}
];


// create the data store
var store = Ext.create('Ext.data.Store', {
    fields: [
       'company',
       'url'
    ],
    data: myData
});

// create the Grid
var grid = Ext.create('Ext.grid.Panel', {
    store: store,
    stateful: true,
    stateId: 'stateGrid',
    columns: [
        {
            text     : 'Company',
            flex     : 1,
            dataIndex: 'company'
        } ,
        {
            text     : 'Image',
            flex: 1,
            renderer : function(value){
                return '<img src="'+value+'">';
            },
            dataIndex: 'url'
        }

    ],
    height: 350,
    width: 600,
    title: 'Array Grid',
    renderTo: 'grid-example',
    listeners: {
        columnhide: function(a, b, c) {
            var cell = this.getEl().query('.x-grid-cell');
            for(var i = 0; i < cell.length; i++) {
                if (i%2 != 0) 
                    cell[i].style.display = "none";

            }
        }
    },
    viewConfig: {
        stripeRows: true
    }
}); 
});

因为 ExtJS 没有提供直接与网格中的行进行通信的方法,所以我尝试查询行,然后修改 DOM。

当然,显示图像列时将应用相反的情况。

The question is rather old, but I think my answer may help someone.

Ext.onReady(function() {
var myData = [
    {company: '3m Co',url: 'logo-small.png'},
    {company: 'Alcoa Inc',url: 'logo-small.png'},
    {company: 'Altria Group Inc',url: 'logo-small.png'}
];


// create the data store
var store = Ext.create('Ext.data.Store', {
    fields: [
       'company',
       'url'
    ],
    data: myData
});

// create the Grid
var grid = Ext.create('Ext.grid.Panel', {
    store: store,
    stateful: true,
    stateId: 'stateGrid',
    columns: [
        {
            text     : 'Company',
            flex     : 1,
            dataIndex: 'company'
        } ,
        {
            text     : 'Image',
            flex: 1,
            renderer : function(value){
                return '<img src="'+value+'">';
            },
            dataIndex: 'url'
        }

    ],
    height: 350,
    width: 600,
    title: 'Array Grid',
    renderTo: 'grid-example',
    listeners: {
        columnhide: function(a, b, c) {
            var cell = this.getEl().query('.x-grid-cell');
            for(var i = 0; i < cell.length; i++) {
                if (i%2 != 0) 
                    cell[i].style.display = "none";

            }
        }
    },
    viewConfig: {
        stripeRows: true
    }
}); 
});

Because ExtJS does not provide a way to directly communicate with the rows in grid, I try querying the rows, then modifying the DOM.

And of course the reverse will be applied when showing the image column.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文