/** * Given a click event, return the Cell that was clicked, or null if the event * did not hit this table. The cell can also be null if the click event does * not occur on a specific cell. * * @param event A click event of indeterminate origin * @return The appropriate cell, or null */ public Cell getCellForEvent(ClickEvent event) { Element td = getEventTargetCell(Event.as(event.getNativeEvent())); if (td == null) { return null; } int row = TableRowElement.as(td.getParentElement()).getSectionRowIndex(); int column = TableCellElement.as(td).getCellIndex(); return new Cell(row, column); }
@PatchMethod static int getCellIndex(TableCellElement element) { TableRowElement row = TableRowElement.as(element.getParentElement()); for (int i = 0; i < row.getCells().getLength(); i++) { if (element.equals(row.getChild(i))) { return i; } } return -1; }
@PatchMethod static int getCellIndex(TableCellElement element) { TableRowElement row = TableRowElement.as(element.getParentElement()); for (int i = 0; i < row.getCells().getLength(); i++) { if (element.equals(row.getChild(i))) { return i; } } return -1; }
/** * Borrowed from CellTable#onBrowserEvent2(Event event) * * @param target * @return */ public static int identifyRow(Element target) { // Find the cell where the event occurred. TableCellElement tableCell = findNearestParentCell(target); if (tableCell == null) { return -1; } // Determine if we are in the header, footer, or body. Its possible that // the table has been refreshed before the current event fired (ex. change // event refreshes before mouseup fires), so we need to check each parent // element. Element trElem = tableCell.getParentElement(); if (trElem == null) { return -1; } TableRowElement tr = TableRowElement.as(trElem); Element sectionElem = tr.getParentElement(); if (sectionElem == null) { return -1; } int row = tr.getSectionRowIndex(); return row; }
int row = TableRowElement.as(td.getParentElement()).getSectionRowIndex(); int column = TableCellElement.as(td).getCellIndex();
/** * Given a click event, return the Cell that was clicked, or null if the event * did not hit this table. The cell can also be null if the click event does * not occur on a specific cell. * * @param event A click event of indeterminate origin * @return The appropriate cell, or null */ public Cell getCellForEvent(ClickEvent event) { Element td = getEventTargetCell(Event.as(event.getNativeEvent())); if (td == null) { return null; } int row = TableRowElement.as(td.getParentElement()).getSectionRowIndex(); int column = TableCellElement.as(td).getCellIndex(); return new Cell(row, column); }
/** * Given a click event, return the Cell that was clicked, or null if the event * did not hit this table. The cell can also be null if the click event does * not occur on a specific cell. * * @param event A click event of indeterminate origin * @return The appropriate cell, or null */ public Cell getCellForEvent(ClickEvent event) { Element td = getEventTargetCell(Event.as(event.getNativeEvent())); if (td == null) { return null; } int row = TableRowElement.as(td.getParentElement()).getSectionRowIndex(); int column = TableCellElement.as(td).getCellIndex(); return new Cell(row, column); }