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.
Create a filter
You can create a filter by using one of the following methods:
- Click the Data Filter icon.
- On the editor toolbar, click the Data Filter icon.
- In the Data Filter pane, click New Filter.
- In the filter edit box, specify a name for the filter and enter the filter code. Then,
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.
- Add a widget to the project and click the Data tab of the right-side panel.
- On the Data tab, select Data Filter and click Add Filter.
- In the Set Data Source pane, click + on the right of Add Filter.
- 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.
Rename a filter
Delete a filter
Add a filter
- On the Data tab of the right-side panel, select Data Filter.
- Click Add Filter.
- 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.
- 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
- In the Set Data Source pane, turn on Filter Debugging under 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. The data input of the filter is presented on the upper part of the box, and the data output on the lower part.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.
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.
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 list and click the Create Code Snippet icon.
- In the Create Code Snippet dialog box, view and modify the name and code of the filter. Then, click OK.
- On the Data Sources tab, click Code Snippets to view the code snippet you created.
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.
- Right-click the filter edit box and select a code snippet to import.
Note You can create and import code snippets to share and use filters across projects.