Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Tooltip in Selectitem

    Hi,
    we use a SelectItem which we fill it with setValueMap.
    I need to show a tooltip when the mouse hovers over the items in the SelectItem (I mean before selecting an entry from the selectitem).
    How can we do this?

    (we are using smartgwt-5.0-2015-08-20) with IE-11).
    Last edited by mf; 24 Oct 2016, 01:25.

    #2
    Hi mf,

    see setItemHoverFormatter().
    My code is:
    Code:
            setItemHoverFormatter(new FormItemHoverFormatter() {
                @Override
                public String getHoverHTML(FormItem item, DynamicForm form) {
                    if (item.getSelectedRecord() == null || item.getSelectedRecord().getAttribute(nameField) == null)
                        return null;
                    String retVal = "<b>" + item.getSelectedRecord().getAttribute(nameField) + "</b><br/><br/>";
                    String description = item.getSelectedRecord().getAttribute(descriptionField);
                    if (description == null)
                        return retVal + i18n.noDescriptionGiven();
                    else
                        return retVal + description;
                }
            });
    Best regards
    Blama

    Comment


      #3
      Above works on a selected SelectItem. But I need a tooltip on the unselected items in the SelectItem (a tooltip for every item).
      For example, it should look like: Click image for larger version

Name:	Picture1.png
Views:	160
Size:	27.7 KB
ID:	240969

      Comment


        #4
        Hi @mf,

        please try this:
        Code:
                ListGridField shortnameLGF = new ListGridField(shortnameField);
                shortnameLGF.setCellFormatter(new CellFormatter() {
                    @Override
                    public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                        if (value != null)
                            if (record.getAttribute(nameField) == null || value.equals(record.getAttribute(nameField)))
                                return value.toString();
                            else
                                return record.getAttribute(nameField) + " (" + value.toString() + ")";
                        else
                            return null;
                    }
                });
        
                [B]shortnameLGF.setHoverCustomizer(new HoverCustomizer() {
                    @Override
                    public String hoverHTML(Object value, ListGridRecord record, int rowNum, int colNum) {
                        String description = record.getAttribute(descriptionField);
                        if (description == null)
                            description = i18n.noDescriptionGiven();
                        return description;
                    }
                });
                shortnameLGF.setShowHover(true);[/B]
                setPickListFields(shortnameLGF);
        Best regards
        Blama

        Comment


          #5
          Hi Blama,
          ok that works, thank you.

          Is it necessary (or better) for this solution that I change my SelectItem to get it's data via fetch-service (setOptionDataSource) instead of using setValueMap?

          Comment


            #6
            Hi mf,

            IMHO: If it works, it works. If key/value is enough for you, this should be fine.
            Otherwise, if your data is static, you could also use a clientOnly DataSource.

            Best regards
            Blama

            Comment

            Working...
            X