This question is almost but not quite identical to GWT CellTable getRowElement throwing IndexOutOfBoundsException , however the accepted answer there is not working for me.
I am trying to get a DataGrid to display a different row and cell from the current view. Sometimes that may be on the same page, mostly not. If the row is on the current page -- either the first page or one that has been manually paged to -- then getting the row using getRowElement(rowIdx - pageStart) works, as per the answer mentioned above.
However, if the row is not on the current page, I have found no way to get the row element.
I have tried calculating the appropriate page and setting the page using SimplePager.setPage(), then trying to get the row element using either the actual row index or the page-start-based index (as well as trying the page before and the page after, just for good measure.) All fail with IndexOutOfBoundsExceptions. I have tried force-firing a RangeChangedEvent after setting the page, but that makes no difference (other than fetching that range of data twice.)
I have also tried not setting the page and trying to get the row element, but trying to get the actual index fails as one might expect as it's not on the current page, and what other index would you otherwise use?
I am using GWT 2.8.1 and running both in a Tomcat container and in SuperDevMode in Eclipse + Chrome.
What am I missing?
Thanks, Linus
Sample log output below:
Set page from 0 to 7
scrollRow:366, scrollCol:4
currentPage:7, start: 350, size: 50
Range start: 350, length:50
getRow:366
java.lang.IndexOutOfBoundsException: Row index: 366, Row size: 2088
getRow:16
java.lang.IndexOutOfBoundsException: Row index: 16, Row size: 2088
getRow:316, // try previous page
java.lang.IndexOutOfBoundsException: Row index: 316, Row size: 2088
getRow:416, // try next page
java.lang.IndexOutOfBoundsException: Row index: 416, Row size: 2088
page:7, rowIdx:366, showRow:366, colIdx: 4 : java.lang.IndexOutOfBoundsException: Row index: 416, Row size: 2088
To give context the code that produces this is
if ( cPage != showPage ) {
GWT.log("Set page from " + cPage + " to " + showPage);
gridPager.setPage(showPage);
}
GWT.log("scrollRow:" + scrollToRow + ", scrollCol:"+ scrollToCol);
GWT.log("currentPage:"+ gridPager.getPage() + ", start: " + gridPager.getPageStart() + ", size: "+ gridPager.getPageSize());
Range range = dataGrid.getVisibleRange();
int start = range.getStart();
GWT.log("Range start: "+ range.getStart() + ", length:" + range.getLength());
TableRowElement row;
try {
int getRow = rowIdx;
GWT.log("getRow:"+getRow);
row = dataGrid.getRowElement(getRow);
} catch (IndexOutOfBoundsException iob0 ) {
GWT.log(String.valueOf(iob0));
try {
int getRow = rowIdx-start;
GWT.log("getRow:"+getRow);
row = dataGrid.getRowElement(getRow);
} catch (IndexOutOfBoundsException iob1 ) {
<snip>
TableCellElement cell = row.getCells().getItem(colIdx);
cell.scrollIntoView();