extjs中grid中行内文本或图片居中显示
我是看了网上写的方法调试自己的代码来实现的,实现的方式是当加载store数据时改变grid的行样式,源码如下:
html代码:
<div id="weatherP_grid-body" class="x-panel-body x-grid-body x-panel-body-default-framed x-panel-body-default-framed x-layout-fit" style="border-top-width: 1px; border-bottom-width: 1px; width: 1356px; height: 464px; left: 0px; top: 99px;">
<div id="gridview-1017" class="x-grid-view x-fit-item x-grid-view-default x-unselectable" style="overflow: auto; -moz-user-select: none; margin: 0px; width: 1354px; height: 462px;" tabindex="-1">
<table class="x-grid-table x-grid-table-resizer" cellspacing="0" cellpadding="0" border="0" style="width:1344px;">
<tbody>
<tr class="x-grid-header-row">
<th class="x-grid-col-resizer-gridcolumn-1042" style="width: 24px; height: 0px;"></th>
<th class="x-grid-col-resizer-rownumberer-1009" style="width: 35px; height: 0px;"></th>
<th class="x-grid-col-resizer-gridcolumn-1011" style="width: 0px; height: 0px;"></th>
<th class="x-grid-col-resizer-gridcolumn-1012" style="width: 100px; height: 0px;"></th>
<th class="x-grid-col-resizer-gridcolumn-1013" style="width: 100px; height: 0px;"></th>
<th class="x-grid-col-resizer-gridcolumn-1015" style="width: 450px; height: 0px;"></th>
<th class="x-grid-col-resizer-xiansId" style="width: 100px; height: 0px;"></th>
<th class="x-grid-col-resizer-gridcolumn-1016" style="width: 535px; height: 0px;"></th>
</tr>
<tr class="x-grid-row">
<td class=" x-grid-cell x-grid-cell-gridcolumn-1042 x-grid-cell-special x-grid-cell-row-checker x-grid-cell-first">
<div class="x-grid-cell-inner " style="text-align: left; ;">
<div class="x-grid-row-checker"> </div>
</div>
</td>
<td class=" x-grid-cell x-grid-cell-rownumberer-1009 x-grid-cell-special ">
<div class="x-grid-cell-inner " style="vartical-align: middle; height: 40px; line-height: 40px; text-align: center; margin: 0 auto; ">1</div>
</td>
<td class=" x-grid-cell x-grid-cell-gridcolumn-1011 ">
<div class="x-grid-cell-inner " style="vartical-align: middle; height: 40px; line-height: 40px; text-align: center; margin: 0 auto; ">3754</div>
</td>
<td class=" x-grid-cell x-grid-cell-gridcolumn-1012 ">
<div class="x-grid-cell-inner " style="vartical-align: middle; height: 40px; line-height: 40px; text-align: center; margin: 0 auto; ">白天</div>
</td>
<td class=" x-grid-cell x-grid-cell-gridcolumn-1013 ">
<div class="x-grid-cell-inner " style="vartical-align: middle; height: 40px; line-height: 40px; text-align: center; margin: 0 auto; ">晴</div>
</td>
<td class=" x-grid-cell x-grid-cell-gridcolumn-1015 ">
<div class="x-grid-cell-inner " style="vartical-align: middle; height: 40px; line-height: 40px; text-align: center; margin: 0 auto; ">../images/sky/白天/暴雪.png</div>
</td>
<td class=" x-grid-cell x-grid-cell-xiansId ">
<div class="x-grid-cell-inner " style="display: table-cell; vertical-align: middle; height: 40px; width: 100px; text-align: center; *display: block; ">
<img alt="白天-晴" src="../images/sky/白天/暴雪.png">
</div>
</td>
<td class=" x-grid-cell x-grid-cell-gridcolumn-1016 x-grid-cell-last">
<div class="x-grid-cell-inner " style="vartical-align: middle; height: 40px; line-height: 40px; text-align: center; margin: 0 auto; "> </div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
ext代码:
1 //当表格加载时改变表格内行的样式,是行内容居中显示,图片
weatherP_grid.getStore().on('load', function(){//设置表格加载数据完毕后,更改表格TD样式为垂直居中
var weatherP_grid = document.getElementById("weatherP_grid");
var tables = weatherP_grid.getElementsByTagName("table");//找到每个表格
for(var k = 0; k < tables.length; k++){
var tableV = tables[k];
if(tableV.className == "x-grid-table x-grid-table-resizer"){
var trs = tables[k].getElementsByTagName("tr");//找到每个tr
for(var i = 0;i < trs.length;i++){
var tds = trs[i].getElementsByTagName("td");//找到每个TD
for(var j = 1;j < tds.length; j++){
var divs = tds[j].getElementsByTagName("div");//找到td下面的div标签
for(var m = 0; m < divs.length; m++){
var imgs = divs[m].getElementsByTagName("img");
if(imgs.length != 0){
//这里一定要设置高度,宽度,宽度要和指定的列的宽度相同
divs[m].attributes[0].nodeValue = "display: table-cell; vertical-align: middle; height: 40px; width: 100px; text-align: center; *display: block; ";
} else {
divs[m].attributes[0].nodeValue = "vartical-align: middle; height: 40px; line-height: 40px; text-align: center; margin: 0 auto; ";
}
}
}
}
}
}
});
代码说明:
weatherP_grid:这个是你ext中设置的grid的ID
tableV.className == "x-grid-table x-grid-table-resizer"):这段代码中涉及到的样式类名是要通过断点调试找到的,因为ext会将grid中解析成heml中的table标签,那这个样式类名就是你那个grid解析成table的样式的类名,我是通过firefox中的firebug找到的
剩下的代码就需要你自己慢慢研究了,花了很长时间搞这个图片居中的问题,大家重视下。
效果图:

extjs中grid中行内文本或图片居中显示的更多相关文章
- EXTJS中grid的数据特殊显示,不同窗口的数据传递
//EXTJS中grid的数据特殊显示renderer : function(value, metaData, record, rowIndex, colIndex, store, view) { v ...
- NSS_04 extjs中grid接收datetime类型参数列
今天在做用户列表时发现, asp.net mvc3的控制器在返回JsonResult结果时, 会把对象内的DateTime类型成员,解析为类似于\/Date(1238606590509)\/的格式 , ...
- Extjs中grid表格中去掉红三角
在编辑Extjs的gridpanel的时候,数据有错误或是修改在每个单元格上都会出现红色的小三角,在每个列上面可以配置allowBlank: false来标识这个不可以为空 有的时候在保存数据时如果不 ...
- Extjs中grid前端分页使用PagingMemoryProxy【二】
在项目中遇到Grid前端分页,本人也是刚接触extjs没多久,为了实现效果,一直找了很久才实现出来,对于代码中的一些也不能详细的说明出来, 不知道能不能帮助到遇到同样问题的朋友,所以将例子代码 ...
- Extjs中grid行的上移和下移
一.将up和down按钮放到tbar中,然后选中grid行即可实现上移和下移 var up = new Ext.Action({ text : 'Up', icon : 'up.png',//或者添加 ...
- Extjs中grid 的ColumnModel 属性配置
一, 用数组的方式配置ColumnModel var colModel = new Ext.grid.ColumnModel([ { header:'编号', dataIndex:'id',width ...
- 64. Extjs中grid 的ColumnModel 属性配置
转自:https://blog.csdn.net/u011530389/article/details/45821945 本文导读:Ext.grid.ColumnModel 该类用于定义表格的列模型, ...
- java本地与树莓派中采用UDP传输文本、图片
今天解决了一个困扰好几天的问题,由于比赛需要,需要用java语言,并采用UDP传输协议,让树莓派与服务器(就是本机)建立连接传输视频,图片. 由于UDP是建立在无连接的协议上,因此就碰到了一个很尴尬的 ...
- extjs中grid对于其中表单的表头的读取以及是否隐藏的判断
//获取grid的表头信息 var columns=baseGrid.columns; alert(columns.length); //判断列是否隐藏并输出表 ...
随机推荐
- 关于function与closure
function 方式 scope function closure expression anonymous function class(this, prototype)
- Web分析日志分析2
http://www.docin.com/p-649515490.html http://wenku.baidu.com/link?url=kB-83fbl1Zc3Y6U2BYLj-lKMWShe8Z ...
- C51指针类型和存储区的关系详解
一.存储类型与存储区关系 data ---> 可寻址片内ram bdata ---> 可位寻址的片内ram idata ---> 可寻址片内ram ...
- Filter plugins ? mutate:
filter { grok { match => [ "message" , "\s*%{IPORHOST:clientip}\s+\-\s+\-\s+\[%{HT ...
- 最小费用最大流MCMF 最小增广
没有写单纯性的...应该不会有卡最小增广的出题人吧...(雾) struct MCMF{ struct tedge{int x,y,cap,flow,w,next;}adj[maxm];int ms, ...
- (转载)APC支持php5.4了
(转载)http://www.neatstudio.com/archives/?article-2061.html 时隔一年多,APC终于又更新了,这次更新最大的就是支持PHP5.4:- Add PH ...
- 给大家介绍款在线压缩JS的工具
首先说下该工具的域名:http://javascriptcompressor.com/ 进入后界面如下: 具体要讲下它的功能点:在线压缩 Javascript 源码可以分不同的压缩级别:比如,一般情况 ...
- Scala 编程(三)基本类型和操作
一些基本类型 值类型 范围 Byte 8位有符号补码整数(-27-27-1) Short 16位有符号补码整数(-215-215-1) Int 32位有符号补码整数(-231-231-1) Long ...
- [置顶] Hibernate运行机理
Hibernate 的缓存体系 一级缓存: Session 有一个内置的缓存,其中存放了被当前工作单元加载的对象. 每个Session 都有自己独立的缓存,且只能被当前工作单元访问. 二级缓存: Se ...
- Struts2学习笔记(二):第一个Struts2应用
一.创建Action类. 创建工程Struts2Demo struts 2中的Action类并不需要继承struts 2中的某个父类,普遍的java类就可以. 在org.sunny.user.acti ...