3

HTMLTable中没有这样的方法:

Cell c =  getCell(row,col);

给定行和列,在 HTML/Flex 表中获取单元格的最有效方法是什么?

4

3 回答 3

2

取决于你想做什么。

如果你想读/写单元格的内容,你可能想要使用HTMLTable#setText(int,int)and HTMLTable#getText(int,int),或者HTMLTable#setWidget(int,int)and HTMLTable#getWidget(int,int),如果单元格的内容是一个小部件。

有更多功能可以读取/写入单元格的属性HtmlTable.CellFormatter链接到 gwt javadoc)及其子类 - 您可以使用它来获取它HTMLTable#getCellFormatter(),也可以将它转换,具体取决于HTMLTable您正在使用的实现。例如,使用单元格格式化程序,您可以设置/删除样式、属性或获取底层Element链接到 gwt javadoc)以获得更直接的控制。

于 2011-11-11T19:35:03.617 回答
1

HTMLTable有以下方法:

  • HTMLTable#isCellPresent(int row, int column)
  • HTMLTable#getWidget(int row, int column)

您可以像这样使用它们编写一个实用方法:

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;
}
于 2011-11-10T18:30:44.477 回答
0

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 }); 
}
于 2011-12-20T05:33:08.747 回答