开发者

How to center an image in a column in an ExtJS GridPanel?

I would like to horizontally center the icon in the column "Data":

How to center an image in a column in an ExtJS GridPanel?

I've got textAlign: center on my column:

How to center an image in a column in an ExtJS GridPanel?

And in the icon renderer function, I'm horizontally centering it开发者_开发百科 with CSS:

How to center an image in a column in an ExtJS GridPanel?

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:

{
   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.

This leads me to think that you need display: block on the image - that should let your margin rule do what you expect.


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>';
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜