Announcement

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

    What's the correct way to render a ListGrid field as a link with a click handler?

    I have a ListGrid where one of the fields needs to appear as an anchor, but when clicked, needs to not perform the default anchor click action, and instead call a click handler.

    I'm trying to use ListGrid.createRecordComponent to build the link, but not sure what kind of component to use (if in fact I should even use this approach). Setting the DataSourceField FieldType to link doesn't work because there's no way to override the default link action.

    Any ideas?

    #2
    According to the FAQ, this is not the right solution, but in my ListGrid.createRecordComponent, I was able to do this by creating a com.google.gwt.user.client.ui.Anchor, and adding that to a com.smartgwt.client.widgets.WidgetCanvas and returning the WidgetCanvas (making sure to set the WidgetCanvas height smaller than default).

    There must be a better way, but I'm not sure what it is.

    Jim

    Comment


      #3
      You should be able to use type 'link'. See the docs on setTarget() to avoid the default action and then add a click handler.

      Comment


        #4
        Thanks David,

        I can set the DataSource type to FieldType.LINK, but Neither DataSource (nor DataSourceLinkField) have the setTarget() method. there's a setTarget() on LinkItem.

        So, in ListGrid.createRecordComponent I created a DynamicForm and LinkItem, put the LinkItem on the form, and returned the form (after calling LinkItem.setTarget("javascript"); and adding the click handler.

        Needless to say, the HTML is much deeper than the WidgetCanvas containing the Anchor :( Both work, but this method follows the recommendations in the FAQ.

        I wish there was just a simple Anchor subclass of Canvas

        Comment


          #5
          You are correct on the DataSourceLinkField. However, from the Yahoo! Web Service example you can set the target via setAttribute:
          Code:
          DataSourceLinkField fullImage = new DataSourceLinkField("link", "Full Image");  
                  fullImage.setValueXPath("Url");  
                  fullImage.setAttribute("target", "_blank");
          Just use "javascript" instead of "_blank".

          Then you should be able to just register a click handler for the cell to do what you want.

          Comment


            #6
            Ah yeah, cool! Thanks :)

            Comment

            Working...
            X