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