Select to view content in your preferred language

Adding Tables and Layers to Table Widget programatically in ExB Dev

211
3
Jump to solution
a month ago
Labels (2)
SerjStol
Frequent Contributor

Hey,

Is there way to add datasource table or layer programatically within the code to Table Widget leveraging the "Add To Table" data action? My custom widget in exb dev 1.14 adds a portal hosted feature layers item (generated by python web tool) to the map using similar logic to Add Data widget by publishing a message the layers get added to map automatically, but not the tables... I need to display my non spatial tables somehow in Table Widget.

Any advice much appreciated!

 

 

0 Kudos
1 Solution

Accepted Solutions
SerjStol
Frequent Contributor

In the end i managed to access and execute "AddToTable" data action programatically, I first create DataRecord[] array from my DataSource that I previously create from my output feature layer. DataSource has function to getSourceRecords(). Then you get the addToTable data action from DataActionManager instance by getting supportedDataActions or you could just getActions() and then invoke executeDataAction method like so. You must obtain your table widget ID, either hard code it or get it programmatically like i do. I could then add non spatial tables or feature layer that are in my output hosted feature layer to Table Widget programmatically 🙂

 

// This will return DataSource
      const incidentDs = await createDataSourceByLayer(outputLyrUrl);
      
      // get records of the data source
      const records = incidentDs.getSourceRecords();
      
      const dataSets = {
        records: records,
        dataSource: incidentDs, 
        name: incidentDs.getLabel() 
      };
      
      // Get data actions, could also use getActions()
      const actions = await DataActionManager.getInstance().getSupportedActions(
        props.id,
        [dataSets],
        DataLevel.DataSource
      );
      console.log("Supported actions:", actions)
      
// get addtotable data action types, but this is an array
      const addToTableAction = actions.addToTable;

      console.log("Add to table aciton", addToTableAction)
      
      if (addToTableAction?.length > 0) {
        
        // Execute add to table action on table widget
        await DataActionManager.getInstance().executeDataAction(
          addToTableAction[0],
          [dataSets],
          DataLevel.DataSource,
          tableWidgetId
        );
         
      } else {
        console.warn("No  actions available.");
      }

 

View solution in original post

3 Replies
Allen_Zhang
Occasional Contributor

Hi SerjStol, you can try updating the table widget's mutableStoreValue "viewInTableObj" and widgetStateProp "dataActionActiveObj" like the add-to-table action. The table widget will do the rest.

The first one will add the data to the table. The second one will open the data's tab.

Allen_Zhang_0-1737342670504.png

 

0 Kudos
SerjStol
Frequent Contributor

Thanks @Allen_Zhang , I will try it, currently managed to get Table Widget Id programatically, next i need to make data sources from the non spatial tables I think, then try use your code to add them to table.

0 Kudos
SerjStol
Frequent Contributor

In the end i managed to access and execute "AddToTable" data action programatically, I first create DataRecord[] array from my DataSource that I previously create from my output feature layer. DataSource has function to getSourceRecords(). Then you get the addToTable data action from DataActionManager instance by getting supportedDataActions or you could just getActions() and then invoke executeDataAction method like so. You must obtain your table widget ID, either hard code it or get it programmatically like i do. I could then add non spatial tables or feature layer that are in my output hosted feature layer to Table Widget programmatically 🙂

 

// This will return DataSource
      const incidentDs = await createDataSourceByLayer(outputLyrUrl);
      
      // get records of the data source
      const records = incidentDs.getSourceRecords();
      
      const dataSets = {
        records: records,
        dataSource: incidentDs, 
        name: incidentDs.getLabel() 
      };
      
      // Get data actions, could also use getActions()
      const actions = await DataActionManager.getInstance().getSupportedActions(
        props.id,
        [dataSets],
        DataLevel.DataSource
      );
      console.log("Supported actions:", actions)
      
// get addtotable data action types, but this is an array
      const addToTableAction = actions.addToTable;

      console.log("Add to table aciton", addToTableAction)
      
      if (addToTableAction?.length > 0) {
        
        // Execute add to table action on table widget
        await DataActionManager.getInstance().executeDataAction(
          addToTableAction[0],
          [dataSets],
          DataLevel.DataSource,
          tableWidgetId
        );
         
      } else {
        console.warn("No  actions available.");
      }