Over the last few versions of 4D Write Pro, many table-related features have been added. You can easily create tables based on database data using contexts, data sources, and formulas.
This is so easy that many of just want to let your end-users use the feature as it is. But we understand this can sometimes be challenging for users who lack training in formatting data sources or formulas for various table components. To address this, we have developed a solution shipped with 4D v20 R2: the brand-new table wizard.
The wizard is available to end-users; they can take advantage of templates adapted to their use and business provided by the developer. Configuring templates includes:
- define dataclass and dataclass attributes,
- translate dataclass, dataclass attributes, and formula names,
- prepare formulas adapted to the business,
- design graphic styles.
Continue reading to find out more, and don’t forget to check out the HDI and watch the bonus video that guides you through various possibilities.
WP table wizard interface
The user can access the wizard via the “Insert table” menu in the toolbar or the side-bar.
The interface is quite simple and amazing. The user selects a template or dataclass and a theme. Then, he checks the fields to be displayed as columns. He can also sort the columns. Next, he can define the number of header rows, summary rows positioned above or below the data, and extra rows. Next, he chooses the formulas to be displayed in the summary or extra rows. Finally, he clicks on the “Insert” button to add the table to the WP document.
Once the table has been integrated into the document, the user can modify or customize its style. The formatting tools of the toolbar and sidebar are still available.
Here’s a video to demonstrate the possibilities:
You can download the HDI and repeat the video example.
How to configure
The wizard consists of 3 types of configuration files.
Template files
The template file allows you to define the following:
- the formula that returns an entity selection used as the table’s data source,
- the dataclass attributes that can be used as table columns,
- the formula for summary rows,
- formulas that can be used in a summary row contextual menu,
- formulas that can be used in a carry-over row contextual menu,
- and the formulas that can be used in an extra row contextual menu.
Template files must be stored in the “Resources/4DWP_Wizard/Templates” folder within your project.
Here’s a brief example of what your file might look like:
{ "tableDataSource": "ds.People.all().orderBy(\"toCompany.name asc, continent asc, country asc, city asc\")", "columns": [{ "check": true, "header": "Firstname", "source": "This.item.firstname" }, { "check": true, "header": "Lastname", "source": "This.item.lastname" }, { "check": true, "header": "Salary", "source": "String(This.item.salary;\"###,###.00\")" } ], "breaks": [{ "label": "Company", "source": "This.item.toCompany.name" } ], "breakFormulas": [{ "label": "Company", "source": "This.item.toCompany.name" }, { "label": "Sum of salaries", "source": "String(This.breakItems.sum(\"salary\"); \"###,###.00\")" } ], "bcorFormulas": [{ "label": "Sum of salaries", "source": "String(This.tableData.sum(\"salary\"); \"###,###.00\")" } ], "extraFormulas": [{ "label": "Sum of salaries", "source": "String(This.tableData.sum(\"salary\"); \"###,###.00\")" } ] }
Look at this detailed documentation page to learn more about JSON format and attribute names.
TranslatION files
Translation files are used to translate the names of templates, themes, tables, fields, and formulas, if necessary. You must add them to your project’s “Resources/4DWP_Wizard/Translations” folder.
If the user selects a dataclass in the interface. The translation file has a second function. It can filter the dataclass and dataclass attributes proposed to the user. For example, to hide table IDs.
Note: This behavior is similar to the SET TABLE TITLES and SET FIELD TITLES commands for those who know the classic language.
Here’s an example of a translation file:
{ "tables": [{ "original": "People", "translation": "Personne" } ], "fields": [{ "original": "lastname", "translation": "Nom" }, { "original": "firstname", "translation": "Prénom" }, { "original": "salary", "translation": "Salaire" }, { "original": "company", "translation": "Société" } ], "formulas": [{ "original": "Sum of salary", "translation": "Somme des salaires" } ] }
In the documentation, all possible attributes are listed and explained.
Theme files
A list of themes is provided by default in the 4D Write Pro Interface component. However, you can create your own theme by placing them in the “Resources/4DWP_Wizard/Themes” folder within your project.
The theme files allow you to define the following WP attributes for a header, data, carry-over, summary, and extra rows:
- textAlign
- backgroundColor
- borderColor
- borderStyle
- borderWidth
- font
- color
- fontFamily
- fontSize
- padding
And also, here is an example of the theme file:
{ "default": { "backgroundColor": "#F0F0F0", "borderColor": "#101010", "borderStyle": 1, "borderWidth": "0.5pt", "font": "Times New Roman", "color": "#101010", "fontFamily": "Times New Roman", "fontSize": "7pt", "padding": "2pt" }, "table": { "backgroundColor": "#E1EAF3" }, "header1": { "textAlign": 2, "borderColor": "#41548F", "borderWidth": "1.5pt", "backgroundColor": "#979BA9", "color": "#F4F4FF", "font": "Times New Roman Bold" }, "data": { "fontSize": "13pt", "textAlign": 0 }, "break1": { "textAlign": 2, "fontSize": "15pt" } }
As for other files, the JSON grammar is available in the documentation.
Next…
The WP table wizard is part of the 4D Write Pro Interface component. The sources are available on Github if you wish to make adaptations.
Feel free to share your impressions or feedback on the forum.