Data List Dynamic Columns¶
Dynamic Columns are a feature for the DataList control that allow you to dynamically calculate the displayed list columns and the respective row values during the runtime based on user-defined data.
Unlike traditional columns that must be defined by a developer at compile time, dynamic columns can create a flexible, data-driven grid structure. This is ideal for scenarios where the data attributes are not fixed, such as handling user-defined custom fields, creating pivot tables, or building reports that must adapt to changing business processes.
With this feature, you can build a DataList that automatically adds or removes columns in response to changes in your
application's data, without requiring any code changes or redeployment.
In the example that follows, we will build an example use case of the dynamic columns feature for an eshop product list, where the columns represent user-defined custom fields that can be defined at runtime by the user. Each unique user-defined field will become a column in the product list.
Creating the domain model and forms¶
Our domain model for the simple eshop application comprises two classes: Product and ProductCustomField as shown
below:
You will also create the respective forms to accommodate data entry.
Finally, we will add some sample data: 2 products, each of which has 2 custom fields, color and material.
Defining the dynamic columns information¶
Next, we will define the methods in the Product class that will provide the dynamic column information. The names of
the functions are user-defined, but the signatures must match exactly as shown.
The first function, DynamicColumns, returns a list of column definitions. Each column definition should include at
least a caption for the header.
static function Collection[CommonLib.ListColumnInfo] DynamicColumns()
{
Collection[CommonLib.ListColumnInfo] info;
foreach string name in Domain.ProductCustomField.GetAll().Select(x => x.Name).Distinct()
{
CommonLib.ListColumnInfo x;
x.Caption = name;
x.ItemType = CommonLib.ColumnItemType.Textbox;
info.Add(x);
}
return info;
}
In this function, we query all existing custom field names from the database and create a column definition for each
unique name. We are also setting the type of the column to Textbox.
The second function, DynamicColumnValues, returns the values to be displayed in all dynamic columns defined in
DynamicColumns for a given product instance. The function takes the product instance as a parameter and returns a list
of values corresponding to each dynamic column, in the same order as defined in DynamicColumns.
static function Collection[CommonLib.ListDynamicColumnValue] DynamicColumnValues(Domain.Product product)
{
Collection[CommonLib.ListDynamicColumnValue] values;
var dynamicColumns = Domain.Product.DynamicColumns();
foreach CommonLib.ListColumnInfo column in dynamicColumns
{
var value = product.CustomFields.First(x => x.Name == column.Caption);
CommonLib.ListDynamicColumnValue x;
if value != null
{
x.DynamicValue = value.Value;
}
else
{
x.DynamicValue = null;
}
values.Add(x);
}
return values;
}
Here, we loop through each dynamic column defined in DynamicColumns, find the corresponding custom field for the given
product, and add its value to the list of values to be returned.
Creating a set of dynamic columns¶
You can add dynamic column logic to any DataList control directly from the Form Editor.
Follow these steps to configure dynamic columns:
-
In the Form Editor, select the DataList control you wish to modify.
-
Add a column in the list control and set its member to any member of the displayed class.
-
Enable the "Dynamic Column" checkbox in the column properties. This will enable 4 more options to the column properties, namely: Get Dynamic Columns Operation's Class, Get Dynamic Columns Operation, Get Dynamic Column Values Operation's Class, Get Dynamic Column Values Operation.
-
Set the references of the function that we created on the previous step as a source of information for the dynamic columns:
-
Compile and run the application. Take a look at the newly created dynamic columns in the product list.
These columns will dynamically expand as new custom fields are added to products without compilation or code changes.
Conclusion¶
As demonstrated, the Dynamic Columns feature fundamentally changes how data can be presented in a DataList. By moving
the column definition from a static, compile-time design to a dynamic, runtime process, developers can create grids that
are truly responsive to the data they display.
This approach is particularly powerful for applications with user-defined data, such as the custom product fields in this example. It empowers business users to extend the data model, and the user interface automatically adapts without requiring developer intervention or a new deployment cycle. This significantly reduces maintenance overhead and increases the agility of the application.
In summary, Dynamic Columns are an advanced feature that enables the creation of sophisticated, self-maintaining reports and comparison tools, providing a level of flexibility that is essential for modern, data-rich enterprise applications.





