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); //判断列是否隐藏并输出表 ...
随机推荐
- COJ 1002 WZJ的数据结构(二)(splay模板)
我的LCC,LCT,Splay格式终于统一起来了... 另外..这个形式的Splay是标准的Splay(怎么鉴别呢?看Splay函数是否只传了一个变量node就行),刘汝佳小白书的Splay写的真是不 ...
- COJ 1011 WZJ的数据结构(十一)树上k大
题解:主席树&DFS序. PS:为什么我一开始Wa了N发 是因为有一个左区间我写成[L,M+1]了.......................... #include<iostream ...
- 【git】git常用命令简介
使用Git也好长时间了,但一直没系统的学习过,现在总结以下工作中用到的,记录以下,以后忘记了可以来看看. 因为操作系统是Windows,所以将简单介绍一下通过git bash命令行的使用: 本文将不介 ...
- freemarker 时间格式化注意事项
${document.publishDate?string("yyyy-MM-dd")} 取出的是 2015-05-20 ${document.publishDate?string ...
- 利用"NOTIFYICONDATA"实现MFC的托盘程序
本文章为转发百度空间内容,,保存一下,以防以后用到.. 一.自定义信息 在头文件中加入下面这句话: #define WM_SHOWTASK (WM_USER+1) 二.MYDLG.CPP文件中添加_m ...
- Web 前端 —— javaScript
目录: 资源链接 基础知识 基础问题集 资源链接: http://www.w3school.com.cn/ 弹出窗口,变暗特效:http://www.csrcode.cn/article-584-1. ...
- (转)Maven实战(六)依赖
我们项目中用到的jar包可以通过依赖的方式引入,构建项目的时候从Maven仓库下载即可. 1. 依赖配置 依赖可以声明如下: <project> ... <dependenci ...
- Demon_游戏登录界面(具备账号密码输入功能)
using UnityEngine; using System.Collections; using UnityEngine.UI;// public class LoginButton : Mono ...
- Android中解析网络请求的URL
近期正在做Android网络应用的开发,使用了android网络请求方面的知识.如今向大家介绍网络请求方面的知识.我们知道android中向server端发送一个请求,(这就是我们通常所说的POST请 ...
- 在Mac中安装.Net Core的开发环境
在mac中部署dotnet core开发环境,我的MacOS版本号为OSX EI Capitan 10.11.6 1.安装brew homebrew官网推荐的安装命令如下: /usr/bin/ruby ...