Dynamic Column by a Dataset Parameter

  • Last update:February 12, 2025
  • Overview

    Version

    Report Server VersionFunctional Change
    11.0

    /

    Expected Effect

    If you use functions to form a dynamic column, all data needs to be fetched. However, the performance may be deteriorated when only data in a few columns are selected from a large amount of data.

    This document introduces an alternative method to form a dynamic column, which allows pagination querying for layered reports in case of a large amount of data and improves report performance, as shown in the following figure.

    Screen Recording 2025-02-11 at 17.35.47 (1).gif

    Implementation Method

    You can form a dynamic column by defining a dataset parameter and dragging the data column to be displayed into corresponding cell.

    Example

    Data Preparation

    New General Report

    1. Create a database query ds1 with the SQL statement SELECT ${col} FROM Sales_Volume. Set the default value of the dataset parameter col to * (string) to query all data, as shown in the following figure.

    2025-02-07_10-06-26.png

    2. Create a database query ds2 with the SQL statement SELECT * FROM Sales_Volume LIMIT 1 to retrieve one data record (containing all field names) from the table, as shown in the following figure.

    2025-02-07_10-06-53.png

    Report Design

    Table Design

    Since you are uncertain about the number of required fields, you need to drag all fields into the template during table design.

    1. Table Header

    Insert formulas from cell A1 to E1. The formulas convert the value of the parameter col into an array and return the 1st to 5th values from the array, respectively.

    The following table describes the formulas.

    Cell
    FormulaDescription

    A1

    INDEXOFARRAY(split($col,","),1)

    INDEXOFARRAY(array,index): returns the No.index element in the array.

    SPLIT(String1,String2): returns an array of strings by splitting String1 using the delimiter String2.

    Since the value of the parameter col is of string type by default, you need to convert the parameter value into an array to obtain the correct returned value.

    B1

    INDEXOFARRAY(split($col,","),2)

    C1

    INDEXOFARRAY(split($col,","),3)

    D1

    INDEXOFARRAY(split($col,","),4)

    E1

    INDEXOFARRAY(split($col,","),5)

    The following figure shows the operation steps.

    2025-02-07_10-49-51.png

    2. Table Content

    Insert data columns from cell A2 to E2. Set Dataset to ds1, enter #1, #2, #3, #4, and #5 into Data Column respectively, set Data Setting to List, and set Expansion Direction to Vertical, as shown in the following figure.

    iconNote:
    #N specifies the index of the column in which data is located in the dataset. For example, #1 specifies data in the first column.

    2025-02-07_10-55-44.png

    Report Border Setting

    Select cells from A2 to E2, click Condition Attribute on the right panel, and click the image.png icon. In the Attribute area, click image.png and select Border from the drop-down list. Click Edit and External in sequence. In the Formula Condition area, set Type to Formula and enter the formula len($$$)!=0, as shown in the following figure. Through this formula, the border is displayed if the cell contains data.

    2025-02-07_14-02-30.png

    Header Background Setting

    Select cells from A1 to E1, click Condition Attribute on the right panel, and click the image.png icon. In the Attribute area, click image.png, select Background from the drop-down list, click Edit, select a blue color, and click OK. Click image.png, select Border from the drop-down list, and click Edit External in sequence. In the Formula Condition area, set Type to Formula and enter the formula len($$$)!=0. Through this formula, the background and border are displayed if the cell contains data. The steps are similar to those in the "Report Border Setting" section, and the following figure shows the setting page.

    2025-02-07_14-00-24.png

    Parameter Widget Setting

    Click the parameter panel and click Add All. Click the widget named col appearing on the parameter panel and select Drop-down Checkbox Widget, as shown in the following figure.

    2025-02-07_14-03-17.png

    Select the drop-down checkbox widget, set Widget Value to String, and clear the default value. Click the image.png icon in Data Dictionary, set Type to Formula, and enter the formula TABLEDATAFIELDS("ds2") in Actual Value, as shown in the following figure.

    2025-02-07_14-52-33.png

    iconNote:
    The default value of the drop-down checkbox widget on the parameter panel must be empty. Otherwise, not all columns can be retrieved.

    Click Event Setting

    If the parameter is empty, all columns are retrieved by default when you click the Query button.

    Click the Query button on the parameter panel, select the Event tab, click the image.png icon, select Click from the drop-down list, add the parameter a with the value set to the formula TABLEDATAFIELDS("ds2") to retrieve all filed names, and enter the following JavaScript codes, as shown in the following figure.

    2025-02-07_14-47-14.png

    The JavaScript codes are as follows:

    var Widget = this.options.form.getWidgetByName("col");  var value =Widget.getValue(); //Get the actual value of the widget.   
    if(value==''||value==null)
    {   /*Get the text widget on the parameter panel and check wh
    ether
    its value
    is empty or null
    before assignment.*/
       Widget.setValue(a);     _g().parameterCommit();     }

    Effect Display

    PC

    Click Pagination Preview. When you select the required data columns and click Query, the data in the corresponding columns will be displayed, as shown in the following figure.

    Screen Recording 2025-02-11 at 17.43.41 (1).gif

    Mobile Terminal

    The report can be previewed on both the DataAnalyst app and the HTML5 terminal. The following figure shows the effect.

     ScreenRecording_02-11-2025 17-57-51_1 (1).gif

    Completed Template

    You can download the template Dynamic Column by a Dataset Parameter.cpt.

    Attachment List


    Theme: Parameter
    • Helpful
    • Not helpful
    • Only read

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

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

    不再提示

    9s后關閉

    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