When Value of Drop-down Box is None, Show All Data

  • Last update:December 23, 2021
  • I. Overview

    1. Problem description

    When you use parameters to query data, if the parameter value in the widget is empty, no data will be displayed after you click Query. As shown below:

    1.png

    We need to achieve the effect that when the parameter value in the widget is empty, click Query, the report will display all the data. That is, when there is no filter, all the data of the report are displayed.

    As shown below:

    2.png


    2. Solution

    You can use template parameters and dataset parameters to query data, and modify the filter and dataset definition method to realize drop-down box selects all when parameter is none.

    II. Example 1: Using template parameters

    1. Create a dataset

    Create a new dataset ds1 and enter the SQL statement SELECT * FROM Sales_Volume to query all the data in the table. As shown below:

    3.png


    2. Define a template parameter

    1) Define a template parameter "Region" and set its default value to "East China". As shown below:

    4.png

    2) Edit the parameters pane, click "Add All", and set the Data Dictionary of the drop-down box widget as Region field in the Sales_Volume table. As shown below:

    5.png


    3. Design the report

    Follow the instructions in the table below to style the report. As shown in the following table:

    CellOperation
    A1~E1The cells write the title fields in sequence: Region, Salesperson, Product Type, Product, and Sales Volume. Select cells A1 to E1 to set the predefined style head bule.
    A2~E2The cells are then dragged into the dataset column fields: Region, Salesperson, Product_types, Product, and Sales_Volume. Select cells A2 to E2 with the font centered.
    A1~E2Select cells A1 through E2 and add a blue border to the table as a whole.

    6.png


    4. Set the filter

    Add Filter to cell A2. Double click A2, select Filter > Common, choose Formula and enter if(len($Region)==0,nofilter,$Region), click Add, click OK, that is, by adding filter to achieve the expected effect. As shown below:

    Note: nofilter said not filter, the formula "if(len($Region)==0, nofilter, $Region) " means that if the parameter "Region" is empty, said don't filter the data, if not empty, the data will filter by "Region".

    7.png

    III. Example 2: Using dataset parameters

    1. Create a dataset

    Set conditions when defining dataset parameters to achieve the expected effect, create a new dataset ds1, enter the SQL statement: SELECT * FROM Sales_Volume WHERE 1=1 ${if(len(Region) == 0,"","and Region = '" + Region + "')} .The default setting parameter is East China, as shown in the following figure:

    8.png

    The statements in the formula are commented as follows:

    WHERE 1=1 indicates that the condition is always true, preventing error when there is no parameter condition.

    len(Region)==0 indicates that the parameter "Region" is empty.

    "Region" between "and Region ='"+Region+" ' " means get the value of parameter, and '+' is a string concatenation symbol.

    ${if(len(Region)==0, ""," and Region = ' " + Region + " ' ")}, said:

    If Region is empty, the query statement is equivalent to the following: SELECT * FROM Sales_Volume

    If Region is not empty, the query statement is equivalent to the following: SELECT * FROM Sales_Volume WHERE 1=1 and Region='${Region}'


    2. Design the report

    Follow the instructions in the table below to style the report. As shown in the following table:

    CellOperation
    A1~E1The cells write the title fields in sequence: RegionSalespersonProduct TypeProduct, and Sales Volume. Select cells A1 to E1 to set the predefined style head bule.
    A2~E2The cells are then dragged into the dataset column fields: RegionSalespersonProduct_typesProduct, and Sales_Volume. Select cells A2 to E2 with the font centered.
    A1~E2Select cells A1 through E2 and add a blue border to the table as a whole.

    9.png


    3. Add the widget

    Edit the parameter pane, click "Add All", and set the Data Dictionary of the drop-down box widget as Region in the Sales_Volume table. As shown below:

    10.png

    IV. Preview effect

    1. PC

    Save the report, then click Pagination Preview to view the effect. As shown below:

    11.gif


    2. Mobile

    The effect of App and HTML5 is the same, as shown below:

    12.gif

    V. Precaution

    Problem description

    After setting according to above, when parameter is empty, we need click query to display all data, how to set preview to display all data without click query?

    Solution

    Uncheck "Display Nothing Before Query" of the parameter pane, as shown below:

    13.png

    VI. Download templates

    1) Example 1

    Please refer to the completed template: %FR_HOME%\webroot\WEB-INF\reportlets\doc-EN\Parameter\Drop-down_Box_Selects_All.cpt

    Click to download the template: Drop-down_Box_Selects_All.cpt

    2) Example 2:

    Please refer to the completed template: %FR_HOME%\webroot\WEB-INF\reportlets\doc-EN\Parameter\Drop-down_Box_Selects_All(Dataset).cpt

    Click to download the template: Drop-down_Box_Selects_All(Dataset).cpt

    Attachment List


    Theme: Parameter
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy