This topic describes how to use a data filter in details. You can create a filter, add a filter, sort filters, and create a code snippet.

  1. Log on to the DataV console.
  2. On the Projects page, click the project you created.
    If no project is available, create a project first. For more information, see Create a project by using a template.
  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 The filter you created by using the Data Filter icon on the toolbar can be called by all widgets in the project. For more information, see Use the data filter. When a filter is called, you can view the dependency between the widget and the filter.
  • Create a filter in the Set Data Source pane of the widget.
    1. Add a widget to the project and click the Data tab of the right-side panel.
    2. On the Data tab, select Data Filter and click Add Filter.Add Filter
    3. In the Set Data Source pane, click + on the right of Add Filter.Add Filter
    4. In the filter edit box, specify a name for the filter and enter the filter code. Then, click Save.

      The created filter appears in the list. You can view the dependency between the widget and data filter.

      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 After you delete a filter, the widgets that call the filter may become unavailable. Proceed with caution.
Move the pointer over a filter in the list and click the Delete icon.Delete a filter

Add a filter

  1. On the Data tab of the right-side panel, select Data Filter.
  2. Click Add Filter.
    Add Filter
  3. In the Set Data Source pane, select an existing filter from the list.

Sort the filters

After you add multiple filters to a widget, you can drag and drop the filters to sort them.

If multiple filters are added to a widget, they filter the widget data in sequence from the top down. 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
  • If one of the filters returns null, this filter is ignored, and the data filtering continues. The system prompts that the output of this filter is null when you configure the filters.
  • If one of the filters encounters an error, the data filtering stops, and the last correct filter result is used.

Debug a filter

  1. In the Set Data Source 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 filter to a widget on the Data tab, if you change the data source type, two errors are reported, prompting that the data source is abnormal.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 Data Filter pane on the left of the project editor, manage all filters in the project and view the dependencies between the filters and widgets. You can call the filters in all widgets in the project.Manage the Data Filter pane
Warning Modifying a filter in the Data Filter pane affects all widgets that call 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.
    Create a code snippet
  3. On the Data Sources tab, click Code Snippets to view the code snippet you created.
    Code Snippets
    Note On the Code Snippets page, you can click Create to create a new code snippet that can be used in your widgets.

    After the code snippet is created, you can proceed with the next step to import the code snippet to a filter.

  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.