Data action

Data action provides a way to process a collection of data records in an extensible way.

The data action is defined by the DataAction interface, which has two important methods: isSupported and onExecute.

  • isSupported will be invoked to check whether the action can process the data. Non-supported data actions will be hidden in the runtime.
  • onExecute will be invoked when a user clicks the data action.

Both methods receive an array of DataRecordSet instance, which contain the data source, the optional data record array, and fields. These two methods receive the DataLevel and widgetId parameters too. The DataLevel is used to indicate whether the DataRecordSet contains all records or a subset of the records.

The framework provides data actions, such as export to CSV and export to JSON. Widgets can provide data actions as well. For instance, the Map widget provides the "pan to" and "zoom to" data actions. Data actions can be implemented in a widget by declaring the data actions in the manifest.json and creating a class that extends the AbstractDataAction.

Some data actions may need to have a setting UI to configure the action behavior. To achieve this, you can declare the settingUri in manifest.json. An action setting UI component is a React component with some injected props. When the user changes the config, you should call this.props.onSettingChange to save the config, which will be available in the onExecute method.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
"dataActions": [
    {
      "name": "showOnMap",
      "label": "Show on map",
      "uri": "data-actions/show-on-map",
      "settingUri": "data-actions/show-on-map-setting",
      "icon": "runtime/assets/icons/ds-map-view.svg"
    }
]

Besides providing data actions, a widget can use data action as well. To use the data actions in a widget, you should declare canConsumeDataAction: true in widget manifest.json properties, then import {DataActionList} from 'jimu-ui' and render the DataActionList in the widget UI.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.