Select to view content in your preferred language

Ideas on how to programmatically set default selection in custom List Widget

793
3
Jump to solution
06-30-2023 10:11 AM
PaulNRWA
Occasional Contributor

I've created a relatively complex dashboard that represents data across all the states.   All my widgets are in-sync and properly update when the user changes selections, etc.   I had a request to provide this dashboard, but at the state level only.   Since I already have a state list widget setup, I was hoping to use everything that is currently working and simply set the selected state in the list widget.   I have the code to determine the state the user is from, but I cannot find a good function to set the default value.

I was trying to over-ride the following function, but I'm not sure the right place to call it from during the loading process.   Everything I've tried, ends up in an endless loop that throws and error.

private readonly selectRecords = (records: DataRecord[]) => {
    const { datasource } = this.state

    if (datasource) {
      MessageManager.getInstance().publishMessage(
        new DataRecordsSelectionChangeMessage(this.props.id, records)
      )

      if (records) {
        this.isMySelected = true
        this.isHasPublishMessageAction = true
        datasource.selectRecordsByIds(records.map(record => record.getId()))
        const outputDs = this.getOutputDs()
        outputDs &&
          outputDs.selectRecordsByIds(records.map(record => record.getId()))
      } else {
        this.isHasPublishMessageAction = false
      }
    }
  }
 
I can easily determine the RecordID to set, but I need to figure out where to call this from during the initial load.   On a related note, any ideas how to disable the widget programmatically, so the user can switch to see other data?   
0 Kudos
1 Solution

Accepted Solutions
PaulNRWA
Occasional Contributor

Thanks Jeffrey.   I was experimenting with some code in that function and will go back and take a closer look.   I agree that it seemed like the logical place to add my code.

View solution in original post

0 Kudos
3 Replies
JeffreyThompson2
MVP Regular Contributor

It looks like a class based React component. I would try setting up a componentDidMount() function.

https://legacy.reactjs.org/docs/react-component.html#componentdidmount

GIS Developer
City of Arlington, Texas
PaulNRWA
Occasional Contributor

Jeffrey - To follow up on the question.   I was able to get the foundation of my code working, by using componentDidUpdate function.   I had to add code to make sure the datasource was "Loaded" and not "Loading".  datasource.getStatus() === DataSourceStatus.Loading    

Once I was sure the dataSource was loaded, I was able to call SelectRecords, using an appropriate DataRecord.

Now it's time to fill in the rest of the code.

0 Kudos
PaulNRWA
Occasional Contributor

Thanks Jeffrey.   I was experimenting with some code in that function and will go back and take a closer look.   I agree that it seemed like the logical place to add my code.

0 Kudos