Question

I am using a CellTable in GWT and trying to add styling to a row whenever certain events happen. The code to add styling is as follows:

Range range = playlistTable.getVisibleRange();
int start = range.getStart();

for (int i = start; i < start + playlistTable.getPageSize(); i++) {

     if (playlistData.get(i) == currentSong) {
            playlistTable.getRowElement(i).addClassName("highlightRow");

     } else {
            playlistTable.getRowElement(i).removeClassName("highlightRow");
     }
 }

When the app loads and the first page of the cell table is displayed, everything works perfectly. However when I scroll to the next page and make a call to the above code, GWT throws an IndexOutOfBoundsException. It does not like my index when I make the call to getRowElement, which only occurs if the index is "not on the current page." It's as though getRowElement always thinks the current page is the first page. If I scroll back to the first page, everything behaves fine. Has anybody encountered this? Am i missing something or is this a bug in GWT?

Was it helpful?

Solution

I suspect the problem is that start is 0 on the page that works. What happens if you do playlistTable.getRowElement(i - start) ? You may have to throw a + 1 or a - 1 in somewhere.

OTHER TIPS

Not a direct answer to your question, but your code would be much simpler with RowStyles

// do it only once!
playlistTable.setRowStyles(new RowStyles<Song>() {
  @Override
  public String getStyleNames(Song row, int rowIndex) {
    return (row == currentSong) ? "highlightRow": "";
  }
});

You might also want to use equals() and/or some ProvidesKey object to compare the row with the currentSong.

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