7

In GWT, I am using CellTable.

When you mouse over the CellTable it highlights each row.

How do change the behavior of the highlighting from the mouse over? Specifically:

  • change the color of highlighting
  • disable/enable
  • make it highlight only the specific grid item at your cursor (instead of the entire row)

( The current hack I have is to create a bunch of 1 column wide CellTables and add them to a VerticalPanel layout... creating the illusion that there is one CellTable and it highlights each grid according to your cursor. Is this bad? Why? performance? )

Trevor Boyd Smith
  • 18,164
  • 32
  • 127
  • 177

3 Answers3

17

You will notice the CellTable uses a ResourceBundle, which means all the css styles get obfuscated ... this makes it more difficult to override styles.

The CellTable constructor will actually allow you to override the default ResourceBundle. So first, you need to create your own resource bundle like this:

public interface CellTableResources extends Resources {

        public CellTableResources INSTANCE =
                GWT.create(CellTableResources.class);

        /**
         * The styles used in this widget.
         */
        @Source("CellTable.css")
        CellTable.Style cellTableStyle();
}

Then you need to create your own CSS file. I recommend copying the CellTable style directly into your project and use that as a starting point. You can find it here: http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/cellview/client/CellTable.css

Make sure the style is injected first, and then you just feed it into the CellTable's constructor like this:

   CellTableResources.INSTANCE.cellTableStyle().ensureInjected();
   myCellTable = new CellTable<T>(Integer.MAX_VALUE,CellTableResources.INSTANCE);

Specifically, you'll want to tweak these styles:

  • cellTableKeyboardSelectedRow
  • cellTableKeyboardSelectedRowCell
  • cellTableSelectedRow
  • cellTableSelectedRowCell
  • cellTableKeyboardSelectedCell

It is important to note that the cell table differentiates between the 'selected row' and the 'keyboard selected row'. The selected row is the actual row selected (ie via SelectionModel). The keyboard selected row refers to what is highlighted when the user is pressing the up / down key, but does not mean the row is actually selected (if that makes sense).

Brad Rydzewski
  • 2,523
  • 14
  • 18
  • 1
    One clarification, i'd recommend copying the CellTableBasic.css style and using it as your baseline: http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/cellview/client/CellTableBasic.css ... the standard CellTable.css stylesheet includes image resources, the CellTableBasic.css is pure css and probably easier to modify – Brad Rydzewski May 16 '11 at 22:13
  • 1
    +1 for your last paragraph where you explain the difference between 'selected row' and the 'keyboard selected row'. that's the first time I've seen it explained – Justin Dec 20 '11 at 15:28
  • How does this help to remove the actual highlighting? I tried overriding all the mentioned styles (including the not mentioned `cellTableHoveredRow` and `cellTableHoveredRowCell`), but I can't get the highlighting to completely disappear. I can change it a bit so it looks different, but I can't remove it. Perhaps someone could share the actual CSS to remove the highlighting on mouse over rows? Thanks. – joscarsson Nov 24 '12 at 12:42
  • Here is code from a gannt chart and table project I did a long time ago. CellTableResources.INSTANCE.cellTableStyle().ensureInjected(); taskTable = new CellTable(Integer.MAX_VALUE,CellTableResources.INSTANCE); https://code.google.com/p/gwtgantt/source/browse/trunk/gwt-gantt/src/main/java/com/bradrydzewski/gwtgantt/table/CellTableResources.css https://code.google.com/p/gwtgantt/source/browse/trunk/gwt-gantt/src/main/java/com/bradrydzewski/gwtgantt/table/CellTableResources.java – Brad Rydzewski Nov 25 '12 at 00:08
4

I'll just add for number 2) on your list, you can simply do

cellList.setSkipRowHoverStyleUpdate(true)

That completely disables highlighting. There are also two more setSkip-functions on CellList related to hovering.

joscarsson
  • 4,789
  • 4
  • 35
  • 43
1
  1. CellTable can be styled via CSS: How do I style a gwt 2.1 CellTables headers?

  2. To disable highlighting just set the hover CSS property to nothing.

  3. Possibly - try tweaking the .cellTableSelectedRow and .cellTableSelectedRowCell.

Here is the original CellTable.css: http://www.google.com/codesearch/p?hl=en#A1edwVHBClQ/user/src/com/google/gwt/user/cellview/client/CellTable.css&q=cellTableLastColumn&d=8

Community
  • 1
  • 1
Peter Knego
  • 79,991
  • 11
  • 123
  • 154
  • Could you please provide some details on how to do number 2 on your list, "just set the hover CSS property to nothing"? Where do I set that property, on which CSS class, etc? Thanks. – joscarsson Nov 24 '12 at 12:45