Search code examples
gridgxt

GXT -coloring entire grid row according to one cell in row


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

Solution

  • 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.