博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Extjs4:改变Grid单元格背景色(转载)
阅读量:4582 次
发布时间:2019-06-09

本文共 1687 字,大约阅读时间需要 5 分钟。

转自:http://joyliu.org/blog/archives/167

在Extjs4的Grid中改变单元格背景颜色,最近项目中也有用到,所以还是做好实例,还是用之前的例子《》,变化的百分比如果是正数用绿色背景色,如果是负数用橙色背景色,先看下效果:

cell改变背景色

  查询api,在grid中需要改变列,单元格属性用的比较多的还是renderer

renderer : FunctionA renderer is an 'interceptor' method which can be used transform data (value, appearance, etc.) before it is rendered. …… Parameters value : Object The data value for the current cell metaData : Object A collection of metadata about the current cell; can be used or modified by the renderer. Recognized properties are: tdCls, tdAttr, and style. ……

看能用上的这个参数metaData,这里可以通过tdCls,tdAttr, 和style去修改单元格的样式和相关的属性

这里我用tdCls和style
①设置style

{
xtype: 'gridcolumn', renderer: function(value, metaData, record, rowIndex, colIndex, store, view) { /* if (value > 0) { return '' + value + '%'; } else if (value < 0) { return '' + value + '%'; }*/ if(value>0){ metaData.tdCls="changeplus"; }else{ metaData.tdCls="changediv"; } return value+'%'; }

②如果是用tdCls,

app.css

.x-grid-cell.changeplus { background-color: #42E61A; } .x-grid-cell.changediv { background-color: #F79709; }

CompanyGrid.js

{
xtype: 'gridcolumn', renderer: function(value, metaData, record, rowIndex, colIndex, store, view) { /* if (value > 0) { return '' + value + '%'; } else if (value < 0) { return '' + value + '%'; }*/ if (value > 0) { metaData.style=' margin: 0px; padding: 0px; color: rgb(102, 102, 0);">; }else{ metaData.style=' margin: 0px; padding: 0px; color: rgb(102, 102, 0);">; } return value+'%'; }, width: 75, dataIndex: 'pctChange', text: '变化百分比' },

两种方式都可以达到相同的效果,可以通过tdAttr来设置单元格的提示,在grid的列中显示的内容比较长是可以用到,还是挺使用的。

转载于:https://www.cnblogs.com/Joetao/articles/4505267.html

你可能感兴趣的文章
完整版本的停车场管理系统源代码带服务端+手机android客户端
查看>>
排序精讲
查看>>
【bzoj3172】 Tjoi2013—单词
查看>>
【uoj2】 NOI2014—起床困难综合症
查看>>
js return的用法
查看>>
子节点填充父元素除去一固定高度后的剩余高度
查看>>
[原]IOS 后台发送邮件
查看>>
(转)JAVA Calendar详解
查看>>
转: 编码,charset,乱码,unicode,utf-8与net简单释义
查看>>
C#--正则匹配
查看>>
5.30 考试修改+总结
查看>>
BA-设计施工调试流程
查看>>
C#-CLR各版本特点
查看>>
css3背景透明文字不透明
查看>>
《java JDK7 学习笔记》之接口与多态
查看>>
LeetCode 96:Unique Binary Search Trees
查看>>
kernel-char设备的建立
查看>>
DVWA-CSRF
查看>>
ubuntu common software introduction
查看>>
资源相互引用时 需添加 PerformSubstitution=True
查看>>