选择一行时,我想知道选择了该行的哪一列。
目前,我会覆盖 onBrowserEvent2
protected void onBrowserEvent2(Event event)
{
// Get the event target.
EventTarget eventTarget = event.getEventTarget();
if (!Element.is(eventTarget)){
return;
}
final Element target = event.getEventTarget().cast();
// Find the cell where the event occurred.
TableCellElement tableCell = findNearestParentCell(target);
if (tableCell == null) {
return;
}
int col = tableCell.getCellIndex();
.... blah ... blah ....
}
在哪里,
//exact replica code from {@link AbstractCellTable} private method findNearestParentCell
private TableCellElement findNearestParentCell(Element elem) {
while ((elem != null) && (elem != getElement())) {
// TODO: We need is() implementations in all Element subclasses.
// This would allow us to use TableCellElement.is() -- much cleaner.
String tagName = elem.getTagName();
if ("td".equalsIgnoreCase(tagName) || "th".equalsIgnoreCase(tagName)) {
return elem.cast();
}
elem = elem.getParentElement();
}
return null;
}
这是唯一的方法吗?是否有一个带有更改事件的选择模型,它会告诉我点击了该行的哪一列。
有没有办法在列或列的单元格上实现点击处理程序?