GXT - 根据行中的一个单元格对整个网格行进行着色

发布于 2024-12-26 21:00:19 字数 1516 浏览 1 评论 0原文

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

 /*------------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); 

. .
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); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

命硬 2025-01-02 21:00:19

鉴于您正在使用 GXT > 2.xx 中,正确的方法是将新的 GridViewConfig 附加到网格视图。

你可能应该这样做:

grid.getView().setViewConfig(new GridViewConfig() {
        @Override
        public String getRowStyle(ModelData model, int rowIndex, ListStore<ModelData> ds) {
            if (model != null) {
                                    //TODO: put your conditions here
                if ("YOUR_CONDITION".equals(model.get("BOOK_COLOR))) {
                    return "green-row";
                }
            }
            return "";
        }
    });

你应该相应地修改你的CSS。 (请注意,green-row 是 css 样式类的名称)。

请参阅此供参考:http://www.jarvana.com/jarvana/view/com/extjs/gxt/2.1.1/gxt-2.1.1-javadoc.jar!/gxt-2.1.1-javadoc/com/extjs/gxt /ui/client/widget/grid/GridViewConfig.html

Given you are using GXT > 2.x.x, the correct way to do this is to attach a new GridViewConfig to your grid's view.

You should probably do something like:

grid.getView().setViewConfig(new GridViewConfig() {
        @Override
        public String getRowStyle(ModelData model, int rowIndex, ListStore<ModelData> ds) {
            if (model != null) {
                                    //TODO: put your conditions here
                if ("YOUR_CONDITION".equals(model.get("BOOK_COLOR))) {
                    return "green-row";
                }
            }
            return "";
        }
    });

You should amend your css accordingly. (note that green-row is a name of a css style class).

See this for reference: http://www.jarvana.com/jarvana/view/com/extjs/gxt/2.1.1/gxt-2.1.1-javadoc.jar!/gxt-2.1.1-javadoc/com/extjs/gxt/ui/client/widget/grid/GridViewConfig.html

時窥 2025-01-02 21:00:19

在每个渲染方法中,您都将模型作为参数之一,因此尝试为每一列设置相同的渲染器,但将“属性”替换为包含项目类型字符串的属性名称。假设您将其称为“itemName”,因此将代码更改为:

model.get("itemName");  

也许需要进行转换,因为 model.get() 应该返回 Object。

现在,在每一列中都将执行相同的检查,并且所有列都应采用一种颜色。
如果这可行,下一步可能是一些优化:如果第一次检查返回一些颜色,将其设置到模型到颜色的哈希图中(或直接作为新属性设置到模型中),并在渲染器中添加一个将检查的条件如果尚未指定颜色。

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");  

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文