# Is it possible to use two different datasources in the same custom widget with DataSourceSelector?

375
4
06-03-2021 05:05 AM
by
New Contributor II

Trying to add another datasource using DataSourceSelector in settings.tsx only change synchronized with the other one, as they both user

useDataSources={this.props.useDataSources}

How do I make it happen?

1 Solution

Accepted Solutions
New Contributor II

Hi,

I'm not sure if this is what you're asking, but the DataSourceSelector component has a isMultiple prop that, when set to true, will allow the user to configure multiple data sources.  There's no way you are expected to know this since the DataSourceSelector component is not documented anywhere.  I discovered this after ~3 days of hacking through work-arounds.

Cheers

4 Replies
New Contributor II

Hi,

I'm not sure if this is what you're asking, but the DataSourceSelector component has a isMultiple prop that, when set to true, will allow the user to configure multiple data sources.  There's no way you are expected to know this since the DataSourceSelector component is not documented anywhere.  I discovered this after ~3 days of hacking through work-arounds.

Cheers

by Anonymous User
Not applicable

Thanks, that's really great.  How in the world did you find that given that the documentation links are broken?

It seems like I have to use a separate DataSourceComponent for each DataSource configured in the settings page - is that correct?

New Contributor II

Hah, I finally found someone's implementation of the component where they pass in a isMultiple prop, in code published on Stack Overflow.  I don't have the link handy, though, sorry.  But, you can also see ESRI's own implementation of it in the Experience Builder source code.  For example, in ...\client\dist\widgets\common\text\src\setting\setting.tsx.

And, yes, I'm mapping over this.props.useDataSources and passing each "useDataSource" to a DataSourceComponent.  This works for me, since I'm summarizing data from each data source, so I use the callback function to pass actual DataSource objects to a summary table.  I'm not sure if this is "correct", but it seems to work.  Hope this helps.

Cheers

by
New Contributor II

Yes it helped. And yes, I find the documentation being somewhat sparse, and in need for another go-around in the Google index carousel.