我是看了网上写的方法调试自己的代码来实现的,实现的方式是当加载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中行内文本或图片居中显示的更多相关文章

  1. EXTJS中grid的数据特殊显示,不同窗口的数据传递

    //EXTJS中grid的数据特殊显示renderer : function(value, metaData, record, rowIndex, colIndex, store, view) { v ...

  2. NSS_04 extjs中grid接收datetime类型参数列

    今天在做用户列表时发现, asp.net mvc3的控制器在返回JsonResult结果时, 会把对象内的DateTime类型成员,解析为类似于\/Date(1238606590509)\/的格式 , ...

  3. Extjs中grid表格中去掉红三角

    在编辑Extjs的gridpanel的时候,数据有错误或是修改在每个单元格上都会出现红色的小三角,在每个列上面可以配置allowBlank: false来标识这个不可以为空 有的时候在保存数据时如果不 ...

  4. Extjs中grid前端分页使用PagingMemoryProxy【二】

        在项目中遇到Grid前端分页,本人也是刚接触extjs没多久,为了实现效果,一直找了很久才实现出来,对于代码中的一些也不能详细的说明出来, 不知道能不能帮助到遇到同样问题的朋友,所以将例子代码 ...

  5. Extjs中grid行的上移和下移

    一.将up和down按钮放到tbar中,然后选中grid行即可实现上移和下移 var up = new Ext.Action({ text : 'Up', icon : 'up.png',//或者添加 ...

  6. Extjs中grid 的ColumnModel 属性配置

    一, 用数组的方式配置ColumnModel var colModel = new Ext.grid.ColumnModel([ { header:'编号', dataIndex:'id',width ...

  7. 64. Extjs中grid 的ColumnModel 属性配置

    转自:https://blog.csdn.net/u011530389/article/details/45821945 本文导读:Ext.grid.ColumnModel 该类用于定义表格的列模型, ...

  8. java本地与树莓派中采用UDP传输文本、图片

    今天解决了一个困扰好几天的问题,由于比赛需要,需要用java语言,并采用UDP传输协议,让树莓派与服务器(就是本机)建立连接传输视频,图片. 由于UDP是建立在无连接的协议上,因此就碰到了一个很尴尬的 ...

  9. extjs中grid对于其中表单的表头的读取以及是否隐藏的判断

    //获取grid的表头信息 var columns=baseGrid.columns;                     alert(columns.length); //判断列是否隐藏并输出表 ...

随机推荐

  1. nterrupt 和 using 在C51中断中的使用

    8051系列MCU的基本结构包括:32个I/O口(4 组8bit 端口):两个16位定时计数器:全双工串行通信:6个中断源(2个外部中断.2个定时/计数器中断.1个串口输入/输出中断),两级中断优先级 ...

  2. ListView OnScrollListener详解(滑屏分页显示数据)

    package com.action; import java.util.ArrayList; import java.util.List; import android.app.Activity; ...

  3. Longest Palindromic Substring——LeetCode

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  4. Letter Combinations of a Phone Number——LeetCode

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  5. [Design Pattern] Factory Pattern 简单案例

    Factory Pattern , 即工厂模式,用于创建对象的场景,属于创建类的设计模式 . 下面是一个工厂模式案例. Shape 作为接口, Circle, Square, Rectangle 作为 ...

  6. 学习微信小程序之css16常见布局

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. YKCW6-BPFPF-BT8C9-7DCTH-QXGWCYQ7PR-QTHDM-HCBCV-9GKGG-TB2TM

    YKCW6-BPFPF-BT8C9-7DCTH-QXGWCYQ7PR-QTHDM-HCBCV-9GKGG-TB2TM

  8. Windows 驱动开发 - 5

    上篇<Windows 驱动开发 - 4>我们已经完毕了硬件准备. 可是我们还没有详细的数据操作,比如接收读写操作. 在WDF中进行此类操作前须要进行设备的IO控制,已保持数据的完整性. 我 ...

  9. 初次使用cocoapods注意事项

    在仅仅用cocoapods时可能会遇到各种各样的错误和问题 这里中总结下: 1.首先使用cocoapods有非常多优点,在github上非常多优秀的开源项目都用到了它;假设你不会使用它,那么非常多优秀 ...

  10. uploadify上传大文件时出现404错误

    出现这个错误的话一般是IIs限制了文件大小.IIS7下的默认设置限制了上传大小.这个时候Web.Config中的大小设置也就失效了.具体步骤:1.打开IIS管理器,找到Default Web Site ...