How to add tooltip to the cells in celltable?

筅森魡賤 提交于 2020-01-03 17:03:44

问题


I am using gwt cellTable. In this cell table i have one column containing compositeCell. Now i want to add a tooltip for all cells in that composite cell. Any work around for this?


回答1:


Here's an abstract tooltip column class that you can extend in place of the normal Column class:

public abstract class MyToolTipColumn<T, C> extends Column<T, C> {

  interface Templates extends SafeHtmlTemplates {

    @Template("<div title=\"{0}\">")
    SafeHtml startToolTip(String toolTipText);

    @Template("</div>")
    SafeHtml endToolTip();

  }

  private static final Templates TEMPLATES = GWT.create(Templates.class);
  private final String toolTipText;

  public MyToolTipColumn(final Cell<C> cell, final String toolTipText) {
    super(cell);
    this.toolTipText = toolTipText;
  }

  @Override
  public void render(final Context context, final T object, final SafeHtmlBuilder sb) {

    sb.append(TEMPLATES.startToolTip(toolTipText));
    super.render(context, object, sb);
    sb.append(TEMPLATES.endToolTip());

  }
}



回答2:


I use this solution:

cellTable.addCellPreviewHandler(new Handler<Object>() {
  @Override
  public void onCellPreview(CellPreviewEvent<Object> event) {
    if ("mouseover".equals(event.getNativeEvent().getType())) {
      cellTable.getRowElement(event.getIndex()).getCells().getItem(event.getColumn()).setTitle('cell contents go here.');
    }
  }
}



回答3:


If you want to add tooltip for the pure GWT table (com.google.gwt.user.cellview.client.CellTable) we can suggest the following lines.

Column<String[], SafeHtml> objectNameColumn = new Column<String[], SafeHtml>(new SafeHtmlCell()) {
    @Override
    public SafeHtml getValue(String[] object) {
        String val = (object[index]==null?"":object[index]); 
        return new SafeHtmlBuilder().appendHtmlConstant("<span title='" + 
            new SafeHtmlBuilder().appendEscaped(val).toSafeHtml().asString() + "'>" + val + "</span>").toSafeHtml();
    }
}; 
cellTable.addColumn(objectNameColumn, colLabel);



回答4:


You can ovveride the render method

@Override
public void render(
    com.google.gwt.cell.client.Cell.Context context,
    String data, SafeHtmlBuilder sb) {

    super.render(context, data, sb);
    sb.appendHtmlConstant(SafeHtmlUtils.
        fromString("<div title=\"" +titleValue + "\"></div>"););

}

Check this also GWT CellTable tooltip not working properly



来源:https://stackoverflow.com/questions/15701665/how-to-add-tooltip-to-the-cells-in-celltable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!