Calling a function from Attribute Table widget?

1735
16
Jump to solution
10-27-2017 07:08 AM
AnnCrystal
New Contributor II

The attribute table widget has a function _switchTable which toggles attribute table. I would like to call it from a off panel widget. I looked into Communication between widgets- but it provides methods to fetchData. I am little confused. Any thoughts? Robert, have done anything in this line?

Thanks in advance

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Ann,

  Ahh, now I see what you were saying about the on event handler. So the issue I see in your code is that _AttributeTable is likely out of scope inside your on event handler. So you need to use lang.htich to get around that.

var _AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");
html.setAttr(this.domNode, 'title', this.label);
d = domConstruct.create('div');
on(d, 'click', lang.hitch(this, function{
  _AttributeTable._switchTable();
}),d);‍‍‍‍‍‍

Or you can use:

this._AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");
html.setAttr(this.domNode, 'title', this.label);
d = domConstruct.create('div');
on(d, 'click', function{
  this._AttributeTable._switchTable();
},d);‍‍‍‍‍‍

View solution in original post

16 Replies
RobertScheitlin__GISP
MVP Emeritus

Ann,

   So do you know how to get a reference to the AT widget in your widget?

0 Kudos
AnnCrystal
New Contributor II

Yes, like this ?: var _AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");   

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ann,

  Then all you have to do is call the method from the _AttributeTable var then.

0 Kudos
AnnCrystal
New Contributor II

Thanks Robert. That's the part which confused me to implement in "on" click event.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ann,

  The on click event in the AT widget just calls that function so all you need to do is call that same fruntion:

_AttributeTable._switchTable();
0 Kudos
AnnCrystal
New Contributor II

Thanks Robert. That part I got- but my "on" implementation is getting wrong. Actually, I was trying to modify a sample code something like this:
var _AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");
        html.setAttr(this.domNode, 'title', this.label);
        d = domConstruct.create('div');
        on(d, 'click', function{
          _AttributeTable._switchTable();

        },d);

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ann,

  Ahh, now I see what you were saying about the on event handler. So the issue I see in your code is that _AttributeTable is likely out of scope inside your on event handler. So you need to use lang.htich to get around that.

var _AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");
html.setAttr(this.domNode, 'title', this.label);
d = domConstruct.create('div');
on(d, 'click', lang.hitch(this, function{
  _AttributeTable._switchTable();
}),d);‍‍‍‍‍‍

Or you can use:

this._AttributeTable = this.widgetManager.getWidgetsByName("AttributeTable");
html.setAttr(this.domNode, 'title', this.label);
d = domConstruct.create('div');
on(d, 'click', function{
  this._AttributeTable._switchTable();
},d);‍‍‍‍‍‍
AnnCrystal
New Contributor II

Thanks Robert. Learning curve is little steep that I thought. But, you are very helpful. Dojo is a strange world with less help. Most of the books are written before 2011. And, there are no good tutorials except one in Pluralsight which is off topic. Sitepen is no longer doing anything with Dojo. So, what's the suggestion on how to get speed on WAB development? Please share your expertise. Thanks

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Ann,

  Look at existing widgets and try to follow the code paths that they take. When you see something that you don't understand like "this.own" or "lang.hitch" search the web for dojo docs on those. Dojo is not going away so I am not sure about:

Sitepen is no longer doing anything with Dojo
0 Kudos