How to givie tooltip for each cell for Datagrid in GWT

2.3k Views Asked by At

I have a Datagrid, where i need to show the value of the each cell in the tooltip.

If i was using celltable then i can easily set title of each cell in the following way.

cellTable.addCellPreviewHandler(new Handler<GWTEvent>() {
  @Override
  public void onCellPreview(CellPreviewEvent<GWTEvent> event) {
    if ("click".equals(event.getNativeEvent().getType())) {
    GWTEvent data1 = event.getValue();
    fireEvent(new ClassicViewWidgetClickEvent(eventsList.get(i).getMessageId()));
    }
    if ("mouseover".equals(event.getNativeEvent().getType())) {
      Element cellElement = event.getNativeEvent().getEventTarget().cast();
      cellElement.setTitle("Bod Message");
    }
  }
}

If i wrote the same logic for Datagrid, its just working for click event. mouseover event is not firing. Why its not firing for Datagrid? Actually my main question is how can i set the tile for each cell in datagrid? Is thee any other alternative. Kindly please reply.

1

There are 1 best solutions below

0
On

For tooltip, create an inner class:

public class MyTooltip extends PopupPanel {
    /**
     * @param html
     *            is to pass tip information.
     */
    @Inject
    public MyTooltip(final HTMLPanel html) {
        super(true);
        setWidget(html);
    }
}

And do the following on mouseover/click of cell,

    final HTMLPanel html = new HTMLPanel("");
    html.getElement().setAttribute("style","padding: 10px;"); // set some style
    html.add(new Label("hello!")); // add widgets
    MyTooltip tooltip = new MyTooltip();
    tooltip.setWidget(html);
tooltip.setPopupPosition(event.getClientX() + 10,event.getClientY() + 10);
    tooltip.show();