Dynamic Columns

Dynamic Columns

SaveToDB products enable you to show, hide, and rename data columns based on query parameters.

Imagine you have a table that contains data for all clients. Each client may require a unique set of columns or specific column names. You can set up mappings between clients and their respective column sets to display only the relevant columns when a user selects a client.

For example, consider a data table (s14.data) with the following columns:

idclient_idid1id2id3string1string2int1int2float1float2
 

The mapping table (s14.view_aliases) is configured as follows:

client_idtable_namecolumn_namealiasis_active
1s14.datafloat1sales
1s14.dataid1state
1s14.datastring1product
2s14.datafloat1sales
2s14.datastring1region
2s14.datastring2manager

To configure dynamic columns, add the mapping table using the DynamicColumns event type in the xls.handlers table:

IDTABLE_SCHEMATABLE_NAMECOLUMN_NAMEEVENT_NAMEHANDLER_SCHEMAHANDLER_NAMEHANDLER_TYPEHANDLER_CODE
 s14dataDynamicColumnss14dynamic_columnsCODE<SQL code>

The SQL code should be:

SELECT
    column_name, alias, is_active
FROM
    s14.view_aliases
WHERE
    client_id = @client_id AND table_name = 's14.data'

This setup ensures that users see specific column names for each client.

You can also use objects of other types instead of inline SQL. Just return the necessary mappings based on the parameter value.

The dynamic column handler must return three columns:

  1. Source column name
  2. Column alias
  3. Visibility flag

The visibility flag can take the following values:

  • NULL: Keep the column visible as is
  • 0: Hide the column
  • 1: Show the column

This website is using cookies. By continuing to browse, you give us your consent to our use of cookies as explained in our Cookie Policy.