问题
There is no such method in HTMLTable:
Cell c = getCell(row,col);
What is the most effective way of getting a cell in an HTML/Flex Table, given the row and column?
回答1:
Depends on what you want to do.
If you want to read/write the content of the cell, you might want to use HTMLTable#setText(int,int)
and HTMLTable#getText(int,int)
, or HTMLTable#setWidget(int,int)
and HTMLTable#getWidget(int,int)
, if the content of the cell is a widget.
There are more functions to read/write properties of the cell in HtmlTable.CellFormatter
(link to gwt javadoc) and its subclasses - you can obtain it using HTMLTable#getCellFormatter()
and maybe cast it, depending on the implementation of HTMLTable
you are using. with the cell formatter you can, for example, set/remove styles, attributes or get the underlying Element
(link to gwt javadoc) for even more direct control.
回答2:
HTMLTable has the following methods:
HTMLTable#isCellPresent(int row, int column)
HTMLTable#getWidget(int row, int column)
You could write a utility method using both of them like this:
public static Cell<?> getCell(HTMLTable table, int row, int column) {
if (table != null && table.isCellPresent(row, column)) {
Widget widget = table.getWidget(row, column);
if (widget instanceof Cell) {
return (Cell<?>) widget;
}
}
return null;
}
回答3:
I di the below code to register the mouseover event whcih will fecth the value of any cell you hover and display it in the tooltip. you can modify the listener for a click and get the same stuff.My code for the event is:
Ext.QuickTips.init();
grid_plancode.on('mouseover', mouseOver);
function mouseOver(e, tar){
var t = e.getTarget();
var overCell = grid_plancode.getView().findCellIndex(t);
var overRow = grid_plancode.getView().findRowIndex(t);
var selectedText=grid_plancode.getView().getCell(overRow, overCell);
if(overCell !== false && overRow !== false) {
Ext.QuickTips.register({target:tar,title:'Value', text:selectedText. innerText });
}
来源:https://stackoverflow.com/questions/8083004/getcellrow-col-in-gwt-htmltable