简体   繁体   English

如何在鼠标悬停在GXT中的网格单元上放置工具提示?

[英]How to put a Tooltip on a Grid Cell in GXT on mouse over?

How can I put a tooltip on a specific grid cell in GXT on mouse over? 鼠标悬停在上方时,如何在GXT中的特定网格单元上放置工具提示

I can put a tooltip for the whole grid, but did not find a way to put for a specific grid cell. 我可以为整个网格放置一个工具提示,但是找不到用于特定网格单元的放置方法。

More specific, how can I retrieve the informations from the grid cell and when the cursor is over the cell, to display some informations from the cell in a tooltip. 更具体地说,我如何从网格单元格中检索信息,以及当光标位于该单元格上方时,如何在工具提示中显示该单元格中的一些信息。

I think the simplest way is to use QuickTip class. 我认为最简单的方法是使用QuickTip类。 This one listens mouseover on some container and shows tip for each children DOM element with qtip attribute presence. 该示例在某些容器上侦听鼠标悬停,并显示具有qtip属性存在的每个子DOM元素的提示。 Example: 例:

public class GxtToolTipInGxtGrid implements EntryPoint {

    public static class Model {
        private final String name;

        public Model(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }

    interface ModelProperties extends PropertyAccess<Model> {
        ValueProvider<Model, String> name();
    }

    private static List<Model> MODELS = Arrays.asList(new Model("John"), new Model("Mary"));
    private static ModelProperties PROPERTIES = GWT.create(ModelProperties.class);

    public void onModuleLoad() {
        ListStore<Model> store = new ListStore<>(Model::getName);
        store.addAll(MODELS);

        List<ColumnConfig<Model, ?>> columns = new ArrayList<>();
        ColumnConfig<Model, Model> column = new ColumnConfig<>(new IdentityValueProvider<>(), 200, "Name with tooltip");
        column.setCell(new SimpleSafeHtmlCell<>(new AbstractSafeHtmlRenderer<Model>() {
            @Override
            public SafeHtml render(Model object) {
                SafeHtmlBuilder sb = new SafeHtmlBuilder();
                //QuickTip will use this attribute (qtip) for showing the tip.
                sb.appendHtmlConstant("<div qtip='" + object.getName() + "'>");
                sb.appendEscaped(object.getName());
                sb.appendHtmlConstant("</div>");
                return sb.toSafeHtml();
            }
        }));
        columns.add(column);
        columns.add(new ColumnConfig<>(PROPERTIES.name(), 100, "Name w/o tooltip"));

        Grid<Model> grid = new Grid<>(store, new ColumnModel<>(columns));
        RootPanel.get().add(grid);
        //Attach QuickTip to grid
        Scheduler.get().scheduleDeferred(() -> new QuickTip(grid));
    }
}

But this is a static approach. 但这是静态方法。 I mean, decision to show tooltip and what to show in tooltip has made on rendering phase. 我的意思是,显示工具提示的决定以及工具提示中显示的内容已在渲染阶段做出。 However, if you need a dynamic approach, then custom implemenation of the QuickTip analogue might be done. 但是,如果需要动态方法,则可以完成QuickTip模拟的自定义实现。

Also, look at Ext GWT (GXT) tooltip over a grid row . 另外,在网格行上查看Ext GWT(GXT)工具提示 It may contains another solutions. 它可能包含其他解决方案。

  1. Register Quicktip on the grid. 在网格上注册Quicktip。

new QuickTip(myGrid) 新的QuickTip(myGrid)

  1. Override the render function of that cell to have a tooltip. 覆盖该单元格的渲染功能以具有工具提示。

      public void render(Context context, ImageResource value, SafeHtmlBuilder sb){ sb.appendHtmlConstant("<div qtip='TOOLTIPVALUE'>"); super.render(context, value, sb); sb.appendHtmlConstant("</div>"); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM