Hi Sam,
I can explain you a little bit about that. I suggest you start by cloning one of the existing sapmple widgets. That makes your life much easier since the JIMU documentation is not very complete. For this case you can use for example:
https://github.com/Esri/arcgis-experience-builder-sdk-resources/tree/master/samples/widgets/feature-...
or
https://github.com/Esri/arcgis-experience-builder-sdk-resources/tree/master/samples/widgets/feature-....
In the sample above the part the dataRender function is where you should be working to get selected features. There, if you change the:
...ds.getRecords().map((r, i)...
to
...ds.getSelectedRecords().map((r, i)...
you will have the selected records. (So I basically changed getRecords with getSelectedRecords).
This should help you to get further.
I share my complete function here in case it helps.
dataRender = (ds: DataSource, info: IMDataSourceInfo) => {
// this.createOutputDs(ds);
const fName = this.props.useDataSources[0].fields[0];
let selectedAttributes = [];
for (let i = 0; i < ds.getSelectedRecords().length; i++){
selectedAttributes.push(ds.getSelectedRecords()[i].getData()[fName]);
selectedAttributes.push(<br/>)
};
// ds.getSelectedRecords().forEach(element => {
// selectedAttributes.push(element.getData()[fName]);
// });
this.setState({
selectedRecords: selectedAttributes
});
return <>
<div>
<p> Selected Records:</p>
</div>
<div className="record-list" style={{ width: '100%', marginTop: '20px', marginBottom: '20px', height: 'auto', overflow: 'auto' }}>
{
ds && ds.getStatus() === DataSourceStatus.Loaded ? ds.getSelectedRecords().map((r, i) => {
return <div key={i}>{r.getData()[fName]}</div>
}) : null
}
</div>
</>
}