This topic describes how to use a data filter, such as creating a filter, adding a filter, sorting a filter, and creating a code snippet.
Log on to the DataV console .
- On the My Visualizations page, click Edit above the project that you created.
- You can perform the following operations in the editor:
Create a filter
You can create a filter by using one of the following methods:
- Click the Data Filter icon.
- In the toolbar of the Visual Editor, click the Data Filter icon.
- In the Data Filter pane, click New Filter.
- In the Filter Settings section, enter a filter name and a custom filter code, and then click Save. The created filter appears in the list.Important The filter created by using Data Filter can be called by any asset in the current visual application. For more information about how to call the filter, see How to use the filter. The dependencies of the asset and filter are displayed when called.
- Create an asset by using the data configuration of the asset.
- Add a random asset to the current visualization application and click the Data icon in the right-side configuration pane.
- In the Data panel, select Data Filter and click Add Filter.
- On the Set Data Source page, click on the right of Filter.
- In the filter edit box, specify a name for the filter and enter the filter code. Then, click Save.
The created filters are listed 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 created filters are also displayed in the Data Filters list. You can also view the dependencies between the filters and the asset in the list.
Rename a filter
Delete a filter
Add a filter
- In the Data configuration panel, select Data Filter.
- Click Add Filter.
- In the Set Data Source step, select an existing filter from the Add Filter drop-down list.
Sort the filters
After you add multiple filters to an asset, you can sort by dragging the filters.
After multiple filters are added to the asset data, the data is filtered from top to bottom, followed by the sorted filters. 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.
- If multiple filters are added to an asset and one of the filters is empty, the filter is ignored but the filtering is not terminated. In addition, the system displays a message on the configuration page of multiple filters.
- If multiple filters are added to an asset and an error occurs when a filter is executed, the filter is terminated and the correct result of the last execution is used.
Debug a filter
- In the Set Data Source section, click Enable Filter Debugging below Data Filter.
- Edit the filter code and click Test. After the debugging is complete, a box appears on the left to show the filter result. As shown in the following figure, the upper and lower parts of the pop-up window on the left show the returned results before and after the data passes through the filter.Important 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 to the Data Assets panel, if you switch the current data source to another data source type, the following two errors are displayed in the Data panel, indicating that the data source configuration is incorrect. Important 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.
Manage the Data Filter pane
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.
- Move the pointer over a filter in the filter list and click the Create Code Snippet icon.
- In the Create Code Snippet dialog box, view and modify the Name and Code, and click OK.
- After the code snippet is saved, click Code Snippet Management on the My Data page to view and manage the code snippet. Note On the Snippet Management page, you can click Create above the snippet list to create a new snippet and save it to the list.
After the code snippet is successfully created, you can proceed with the following steps to import the code snippet to the asset for application.
- Right-click the code editor and select an existing code snippet in the Import dialog box to import the code snippet. Note You can create and import code snippets to share and use filters across projects.