简体   繁体   English

如何将图像居中在ExtJS GridPanel的列中?

[英]How to center an image in a column in an ExtJS GridPanel?

I would like to horizontally center the icon in the column "Data": 我想在“数据”列中水平居中图标:

在此输入图像描述

I've got textAlign: center on my column: 我有textAlign:在我的专栏中心

在此输入图像描述

And in the icon renderer function, I'm horizontally centering it with CSS : 在图标渲染器功能中,我使用CSS水平居中:

在此输入图像描述

Yet it is still left-aligned. 但它仍然是左对齐的。

What else do I have to do so that the icon in the column is centered horizontally? 我还需要做什么才能使列中的图标水平居中?

Adding align: 'center' to the actioncolumn item did the trick, like so: 将align:'center'添加到actioncolumn项就可以了,就像这样:

 { xtype: 'actioncolumn', text: 'Edit', align: 'center', items: [{**}] } 

This is somewhat of a guess, because I don't have anything to test. 这有点猜测,因为我没有任何东西需要测试。

I notice that margin: 0 auto isn't working to center the image. 我注意到margin: 0 auto无法使图像居中。

This leads me to think that you need display: block on the image - that should let your margin rule do what you expect. 这导致我认为你需要display: block图像 - 这应该让你的margin规则做你期望的。

Maybe you need to change the render function like this: 也许您需要像这样更改渲染功能:

function renderDataIcon(val) {
    if(val=='online') {
        return '<div style="width:100%;height:16px;background-image:url(/images/icon_yellow_dot.png);background-position:center center;background-repeat:no-repeat;">&nbsp;</div>';
    } else {
        return '<div style="width:100%;height:16px;background-image:url(/images/icon_red_dot.png);background-position:center center;background-repeat:no-repeat;">&nbsp;</div>';
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM