GXT-根据行中的一个单元格对整个网格行着色 [英] GXT -coloring entire grid row according to one cell in row

查看:113
本文介绍了GXT-根据行中的一个单元格对整个网格行着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

。 。
我根据单元格的值为一列着色,但我想在gxt网格中对整行进行着色(意味着单元格包含的行),帮助我
这里是我为单元格着色的代码(我想要颜色行而不是单元格)

. . I colored one column according to the value of cell but i want to color the entire row (means the cell contained row ) in gxt grid help me here is my code for coloring the cell (i want to color the row instead of the cell)

 /*------------Coloring Area------------*/
                    GridCellRenderer<BeanModelType> ColoredGrid = new GridCellRenderer<BeanModelType>() {

                        @Override
                        public Object render(BeanModelType model,
                                String property, ColumnData config,
                                int rowIndex, int colIndex,
                                ListStore<BeanModelType> store,
                                Grid<BeanModelType> grid) {

                            String valueOfCell =  model.get(property);    
                            String style = valueOfCell.equals("Book") ? "GREEN":
                            valueOfCell.equals("Ersr") ? "red":
                            valueOfCell.equals("Pen") ? "yellow":
                            valueOfCell.equals("comp") ? "blue": "";
                            //Config is the cell and we are setting style here

                            config.style ="background-color:"+style;
                            return valueOfCell; 



                        }    

                        };  
                        System.out.println("COLORRRRR   "+cleanColoredGrid.toString());
                        column.setRenderer(ColoredGrid);  

                    /*-------------Coloring Area Ends-------*/
                    configs.add(column); 


推荐答案

,所以尝试为每个列设置相同的渲染器,但将'property'替换为保存具有item类型的字符串的属性名称。假设你把它叫做'itemName',所以把你的代码改为:

In every render method you got model as one of parameter, so try to set the same renderer to each column, but replace 'property' to name of attribute which holds string with type of item. Let's suppose you called it 'itemName', so change your code to:

model.get("itemName");  

可能需要cast,因为model.get()应该返回Object。

Maybe casting will be required, because model.get() should return Object.

现在在每列中都会执行相同的检查,并且所有检查都应该使用同一种颜色。
如果可行,下一步可能会进行一些优化:如果第一次检查返回某种颜色,请将其设置为模型到颜色的哈希映射(或直接作为新属性添加到模型中),并在渲染器中添加一个条件,将检查颜色是否已被分配。

Now in every column the same check will be performed and all of them should be in one color. If that will work, next step could be some optimizations: if first check returns some color, set it into hashmap of model-to-color (or into the model directly as a new attribute) and add in the renderer a condition which will check if color wasn't already assigned.

这篇关于GXT-根据行中的一个单元格对整个网格行着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆