Tips for dynamically resizing table columns in the Docentric AX designer

These tips apply if you have a table with columns that can be hidden at runtime. The figure below shows such a scenario with tables created with the Group tagging element. Although the Group tagging element contains only one table in the template, it uses Visual Format definitions that dynamically hide some columns at runtime so that the number of columns in the generated report varies.

Tables with hidden columns are narrower by default. We will now learn how to dynamically resize other columns so that the table still takes up the entire width of the page.

How to hide a table column

First, we will see how we can hide the column in Docentric AX designer. The Visual Format property allows us to do this.

The screenshot above shows the visibility settings for a table column:

  1. Select the column for which you want to set the visibility of the column
  2. Click the Visual Format button
  3. Click the plus sign to open the dialog
  4. Select This table column in the Target field
  5. Add the expression that should control the visibility of this column. If the expression returns “true”, the column will be displayed in the report, otherwise it will be omitted from the output.

Once the Visual Format is set for a field, the rainbow circle icon will appear next to the field as you can see in the screenshot above for the @ItemId field.

The image above shows what the template looks like. The Live Preview on the left shows the result. Tables #1 and #2 have some hidden columns. In the Element Tree, we can see that the Visual Format properties are set for three fields. The currently selected field is @LineAmount, which also uses Visual Format. Arrow # 5 shows the icon that explains what type of Visual Format is set. In this case, it is the visibility of the column.

The easiest was to dynamically resize the table

Word offers you several ways to change the size of the table and its columns. Once you have selected the table, you can select Layout > Autofit and choose between three available options:

  • AutoFit Contents resizes the columns based on their content
  • AutoFit Window always uses the entire page width to resize the table
  • Fixed Column Width sets the column width and no longer adjusts it automatically.

In our scenario, we will choose AutoFit Window. This will ensure that each of our tables uses the entire page width, even if some columns are hidden. The result will look like this:

In the first two tables, the width of the visible columns was dynamically adjusted. All visible columns were adjusted proportionally in each of the tables. This will probably be sufficient for most scenarios.

Allow resizing only for certain columns

When we selected AutoFit Window, the tables and columns were resized to fill the entire page width, but the columns for the same field have different widths, as highlighted below for the column which shows Qty field values.

2024-08-23 20_44_05-BasicTrainingTestTemplate_for_Forum_article.docx - Word

Sometimes we want to have more control over the resizing of columns. For example, we may want to keep most columns the same size and only resize one or two columns. Let’s take a look at how to do this.

Our starting point is the table in which we have selected AutoFit Window. Select the table, right-click on it and make sure you have selected the Table tag. Then change the Measure in field from Percent to Inches (or Centimeters if you are using metric units).

Then select the Column tag and click Previous Column or Next Column until you have selected the first table column (see #1 below). Change the selection in the Measure in field from Percent to Inches (or Centimeters).

Select the second column by clicking Next Column. Delete the value for the width here and remove the checkmark from the Preferred width checkbox (see screenshot below). This allows the size of this column to be adjusted dynamically. You can leave the other columns as they are.

When you close the Table Properties dialog, the size of the table columns is adjusted according to the settings, as shown in the following figure. All columns, with the exception of the Name column, use a fixed width in all tables. The column with the Name field is dynamically adjusted depending on how many columns are hidden.

2024-08-23 21_17_51-BasicTrainingTestTemplate_for_Forum_article.docx - Word

Limitations

This solution won’t work if you have merged cells in the table.