Articles in this section
Category / Section

How to Dynamically Rearrange Table Columns Using Code Modules in Bold Reports

Published:
Updated:

In Bold Reports, you can dynamically rearrange table columns by utilizing code modules and report parameters. This technique enables you to define the column order through parameter values, offering flexibility and interactivity in your report design. It’s especially useful when applying custom column arrangements based on business rules or user preferences.

This guide outlines the steps to configure dynamic column reordering using code modules in Bold Reports.

Steps to Dynamically Rearrange Table Columns

  1. Write a Custom Function in a Code Module
    • Open Bold Reports Designer.
    • Go to Report Properties and click the Code button.
    • Paste the following function into the code module dialog to extract the column name from a parameter based on its name:
      image.png
   Public Function GetColumnValue(ByVal columnNum as Integer, ByVal parameter as Parameter) as String 
       Return parameter.Value(columnNum-1) 
   End Function

The GetColumnValue function retrieves a column name from a multi-value parameter based on the specified column number, enabling dynamic column ordering during report runtime.

  1. Create a Multi-Value Parameter

    • Click the Parameters icon to create a new Multi value report parameter to define the column order.
    • Assign default values that match the table’s column names (e.g., Login Id, Employee Id, Title, Manager Id).
      image.png

NOTE:
Ensure the parameter values exactly match the dataset field names as they are available in the DataSet.

  1. Set Expressions for Table Columns Using the Code Module
    • Configure Table Headers:
      In the table’s header row, set the expression for each column header using the code module function.
      image.png
=Code.GetColumnValue(1, Parameters!Order) 

This sets the header text to the first column name specified in the Order parameter.

  • Configure Table Detail Rows
    In the details row of the table, set the expression for each cell to dynamically retrieve the field value based on the column order.
    image.png
=Fields(Code.GetColumnValue(1, Parameters!Order)).Value 

This retrieves the value of the field corresponding to the first column name in the Order parameter.

  1. Save and Preview
    When you preview the report, the table columns will rearrange dynamically based on the values selected in the Order parameter.
    Order:
    image.png

    Re-Ordered type 1:
    image.png

You can download a sample report demonstrating this feature from here.

See Also

Was this article useful?
Like
Dislike
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied