This topic describes how to use data filters, including creating filters, adding filters, sorting filters, and creating code snippets.

  1. Log on to the DataV console.
  2. On the Projects page, click Edit above the project that you created.
  3. Perform the following operations in the project editor:

Create a filter

You can create a filter by using one of the following methods:

  • Click the Data Filter icon.
    1. On the editor toolbar, click the Data Filter icon. Data Filter icon
    2. In the Data Filter pane, click New Filter.
    3. In the filter edit box, specify a name for the filter and enter the filter code. Then, click Save. New Filter
      The created filter appears in the list.
      Notice A filter created by using a Data Filter can be called by any asset in the current visualization application. For more information, see Use the Data Filter. After being called, the dependencies between the asset and the filter are displayed.
  • Create by using the data configuration of the asset.
    1. Add a random asset to the current visualization application. Click the Data icon in the right-side configuration panel.
    2. On the Data tab, select Data Filter and click Add Filter. Add Filter
    3. On the Set page, click The Add icon to the right of Filter. Add Filter
    4. In the Data Filter, specify a name for the filter and enter the filter code. Then, click Save.

      The created filters are arranged and displayed in the data filter list, and the dependencies between the filters and assets are displayed.

      When you configure the internal data of an asset, the new filters are also listed in the Data Filter list, and the dependencies between the filters and the asset are displayed in the list. Dependency between the widget and data filter

Rename a filter

Move the pointer over a filter in the list, click the Rename icon, and enter a new filter name. Rename a filter

Delete a filter

Warning The delete filter operation may cause related assets to become unavailable. Please confirm the operation later.
Move the pointer over a filter in the list and click the Delete icon. Delete a filter

Add a filter

  1. In the Data panel, select Data Filter.
  2. Click Add Filter.
    Add Filter
  3. In the Set pane, select an existing filter from the list.xxx

Sort the filters

After you have added multiple filters to an asset, you can drag the filters to sort them.

After multiple filters are added to the asset data, the data is filtered from top to bottom in sequence. The input of the first filter is the data returned by the data source, the input of the second filter is the output of the first filter, and so on.

Notice
  • When multiple filters are added to an asset, if the return value of a filter in the middle is empty, the filter will be ignored, but the filter will not be terminated, and the system will prompt on the multiple filter configuration page.
  • When multiple filters are added to an asset, if a filter execution reports an error, the filter will terminate and use the correct result of the previous execution.

Debug a filter

  1. In the Set pane, turn on Filter Debugging under Data Filter.
  2. Edit the filter code and click Test.
    After the debugging is complete, a box appears on the left to show the filter result. The data input of the filter is presented on the upper part of the box, and the data output on the lower part. Debugging result
    Notice Filter debugging ensures that the filter code is correct, but it is not applicable to widgets that contain a large volume of data.

Data Source and Filter errors

  • Data Source Error: After you add a data filter in the Data Assets panel, if you switch the current data source to another data source, the following two errors are displayed in the Data Sources panel, indicating that there is a problem with the data source configuration. Data source error
    Notice When the data source is abnormal, the data it returns is incorrect. Therefore, the data filter does not filter data and is dimmed on the Data tab.
  • Filter error: If the filter encounters an exception when it filters data, an error is reported in both the filter and the filter output.
    Figure 1. Error in the filter
    Error in the filter
    Figure 2. Error in the filter output
    Error in the filter output

Manage the Data Filter pane

In the left-side Data Filter panel, you can manage the filters of all assets in the application and view the dependencies between the filters and assets. Filters in the panel can be added and used by any asset in the visualization application. Manage the Data Filter pane
Warning When you modify the content of a filter in the Filter panel, it affects all assets that depend on this filter. Proceed with caution.

Create and import a code snippet

You can create a code snippet from a filter and import the code snippet to the filter. This allows you to call the filter across projects.

  1. Move the pointer over a filter in the list and click the Create Code Snippet icon.
    Create Code Snippet icon
  2. In the Create Code Snippet dialog box, view and modify the Name and Code of the filter. Then, click OK.
    code
  3. On the Data Sources tab, click Code Snippets to view the code snippet you created.
    Code Snippets
    Note You can also click Create at the top of the Code Snippets page to create a new code snippet and save it to the asset list.

    After the code snippet is created, perform the following steps to import the code snippet to the asset for application.

  4. Right-click the filter edit box and select a code snippet to import.
    Import a code snippet
    Note You can create and import code snippets to share and use filters across projects.