Question

So I am a little confused with how to set the css of an individual row in my Datagrid (which as i understand it can use everything the cellTable can use).

First I have a double click and single click handler which do get correctly called in 'onCellPreview'(had to remove selectionModel for this to work). I then can get the row number through event.getIndex().

Next is where I fail in attempt to set the CSS for the selected row, my code:

int Row= event.getIndex();

myDataTable.setRowStyles(new RowStyles<String[]>(){
   @Override
   public String getStyleNames(String [] rowObject, int theRow){
      if (row== theRow){
          return "myDataGridSelectedRow";
      }
      else 
          return "myDataGrid";
   }
});

However I don't understand how this is supposed to work (which is perhaps why I can't get it to work)

  1. How does getStyleNames() get called? It just steps over it in my debugger.
  2. where should the setRowStyles method call be located in my code?
  3. I suppose for this to work properly i must remove the call

     myDataTable.setStyleName("myDataGrid");
    
  4. There is also a pre-existing css class in my DataGridOverride.css(which is different from the main css file where "myDataGrid" is located). The class is ".dataGridSelectedRowCell" and has a background color set (uses !important) but it does not work.
Was it helpful?

Solution

This method setRowStyles() is called only when a table is rendered.

You can set a style dynamically this way:

myDataTable.getRowElement(i).getStyle()...

or

myDataTable.getRowElement(i).setClassName("myDataGridSelectedRow");

You do not need to remove style name from your grid.

EDIT:

An alternative approach is to override the standard DataGrid CSS Resource:

How do I style a gwt 2.1 CellTables headers?

I would recommend this approach if you want to make many changes to default GWT DataGrid styles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top