关注JEECG发展历程 关注最新动态和版本, 记录JEECG成长点滴 更新日志 - 技术支持 - 招聘英才

JEECG最新版本下载 JEECG智能开发平台 - 显著提高开发效率 常见问题 - 入门视频 - 参与开源团队

商务QQ: 69893005、3102411850 商务热线(5*8小时): 010-64808099 官方邮箱: jeecgos@163.com

查看: 10898|回复: 1

<t:dgCol 如何给单元格设置不同的颜色

[复制链接]
发表于 2013-7-20 17:51:43 | 显示全部楼层 |阅读模式
这个功能下个版本就会支持,我这里先爆下,因为有童鞋问到,easyui 有提供style设置的.这个是我们的基本前提
后面就是我们的修改:
首先我们先在这个类DataGridColumnTag 里面添加一个属性
  1. protected String style; //Td的CSS
复制代码
然后这个他的set方法,get就不用了,之后
  1. public int doEndTag() throws JspTagException {
  2.                 Tag t = findAncestorWithClass(this, DataGridTag.class);
  3.                 DataGridTag parent = (DataGridTag) t;
  4.                 parent.setColumn(title,field,width,rowspan,colspan,align,sortable,checkbox,formatter,hidden,replace,treefield,image,query,url,funname,arg,queryMode, dictionary,frozenColumn,extend,style);
  5.                 return EVAL_PAGE;
  6.         }
复制代码
这里面加入我们添加的style,下一步,我们去DataGridTag这个tag大类里面去添加
  1. protected List<ColumnValue> columnStyleList = new ArrayList<ColumnValue>();// css替换集合
复制代码
这个这样我们把我们先放入的值存放到columnStyleList里面,再回到上面提到的public void setColumn()
这个方法,添加
  1. dateGridColumn.setStyle(style);//这个是必须的,不然怎么设置啊,对不
复制代码
  1. if(StringUtil.isNotEmpty(style)){
  2.                         String[] test = style.split(",");
  3.                         String text = "";
  4.                         String value = "";
  5.                         for (String string : test) {
  6.                                 text += string.substring(0, string.indexOf("_")) + ",";
  7.                                 value += string.substring(string.indexOf("_") + 1) + ",";
  8.                         }
  9. <b>                        setStyleColumn(field, text, value);</b>
  10.                 }
复制代码
再新增这个方法
  1. /**
  2.          * 设置CSS换值
  3.          * @param field
  4.          * @param text
  5.          * @param value
  6.          */
  7.         private void setStyleColumn(String field, String text, String value) {
  8.                 ColumnValue columnValue = new ColumnValue();
  9.                 columnValue.setName(field);
  10.                 columnValue.setText(text);
  11.                 columnValue.setValue(value);
  12.                 columnStyleList.add(columnValue);
  13.         }
复制代码
这样我们就把前台穿过来的css值存放起来了,下面只需要在最后的向前台输入里面添加就可以了
还有记得要添加清除哈
  1. public int doStartTag() throws JspTagException {
  2.                 // 清空资源
  3.                 urlList.clear();
  4.                 toolBarList.clear();
  5.                 columnValueList.clear();
  6.                 columnStyleList.clear();
  7.                 columnList.clear();
  8.                 fields = "";
  9.                 searchFields = "";
  10.                 return EVAL_PAGE;
  11.         }
复制代码
继续我们的,接下来我们找这个方法
  1. /**
  2.          * 拼接字段
  3.          *
  4.          * @param sb
  5.          * @frozen 0 冰冻列    1 普通列
  6.          */
  7.         protected void getField(StringBuffer sb,int frozen) {
复制代码
这个方法就是拼装字段的,也就是现实字段的属性
我们在这个方法里面添加我们的style字段---在值替换的下面
  1. if (columnStyleList.size() > 0 && !column.getField().equals("opt")) {
  2.                                 String testString = "";
  3.                                 for (ColumnValue columnValue : columnStyleList) {
  4.                                         if (columnValue.getName().equals(column.getField())) {
  5.                                                 String[] value = columnValue.getValue().split(",");
  6.                                                 String[] text = columnValue.getText().split(",");
  7.                                                 sb.append(",<b>styler:function</b>(value,rec,index){");
  8.                                                 for (int j = 0; j < value.length; j++) {
  9.                                                         testString += "if(value=='" + value[j] + "'){return \'" + text[j] + "\'}";
  10.                                                 }
  11.                                                 sb.append(testString);
  12.                                                 sb.append("else{return value}");
  13.                                                 sb.append("}");
  14.                                         }
  15.                                 }
  16.                                
  17.                         }
复制代码
注意上面的加粗字体,这个就是easyui的方法,进行是style设置
好了到此就大功告成了后台只有在easyui.tld里面的DataGridColumnTag添加我们新增的属性
  1. <attribute>
  2.    <name>style</name>
  3.    <required>false</required>
  4.    <rtexprvalue>true</rtexprvalue>
  5.    <description>td CSS 属性</description>
  6.   </attribute>
复制代码
c再重启下tomcat就可以使用了
  1. <t:dgCol title="jueyue" field="jueyue" replace="是_Y,否_N" style="background:red;_N" ></t:dgCol>
复制代码
下面展示下效果吧 QQ图片20130720175033.jpg 就变成红色了
到此结束,第一次写这么多....


发表于 2013-8-7 11:39:13 | 显示全部楼层
试一下!!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表