Since the tables in 4D Write Pro can be populated by datasources, numerous functions have been added to personalize them as much as possible. These include formulas linked to datasources, break rows, bottom carry over rows, etc.
4D 20 R6 refines table behavior with a new attribute: wk empty datasource. This attribute allows you to define how tables render when their linked datasource is empty, providing greater control over document presentation.
HDI: Manage Empty Datasources!
A new table attribute: wk empty datasource
This new attribute defines a table’s behavior when its associated datasource is empty (each table can have different settings). This attribute is only considered if a datasource is associated with the table. If this is not the case, it will be ignored. Similarly, it will only be considered when the datasource is empty.
Here are your options:
- Show data row (default)
- Hide the data row
- Hide the entire table
- Display a placeholder row
If a datasource is empty, you may still want to keep (display) the header rows (up to 5 possible rows, as a reminder) and the rows that follow the data row (the data row being the row repeated for each element in the datasource). If this option is selected, neither the data row nor the breaks (if any) will be displayed.
WP SET ATTRIBUTES($table; wk empty datasource; wk hide data row)
In other cases, a table may no longer be interesting if its datasource is empty. In this case, the solution is not to display the table.
WP SET ATTRIBUTES($table; wk empty datasource; wk hide table)
At least, when the datasource is empty, you may want to display a placeholder row specially designed for this purpose instead of the regular data row.
WP SET ATTRIBUTES($table; wk empty datasource; wk show placeholder row)
For completeness, there is a fourth option: wk show data row. This value—which is actually the default value—will be used if you reset the attribute with the WP RESET ATTRIBUTES command.
WP SET ATTRIBUTES($table; wk empty datasource; wk show data row)
// is equivalent to
WP RESET ATTRIBUTES($table; wk empty datasource)
Import/export
Whatever the value chosen for this new option, it will be applied when exporting, regardless of the format selected.
Docx, HTML, SVG, PDF… in all cases, the tables will be represented (or not) depending on the chosen options.
TABLE WIZARD IMPROVEMENTS
Do you remember the table wizard? If not, you may never have used it. Follow the following link to learn more about it!
So, the table wizard has not been forgotten. Thanks to a new item in the interface, you can define this setting!
If you choose “Show placeholder row,” the wizard will automatically add a new row labeled [D’] for you!
The appearance of the placeholder row can be defined in the themes (inside the resources folder) JSON files thanks to a new “placeholder” entry.
"placeholder": { "color": "#202020", "fontSize": "10pt", "backgroundColor": "yellow" }
The same goes for the formulas that can be inserted by a contextual menu. A new entry, placeholderFormulas, has been defined in the “templates” JSON files inside the resources folder.
"placeholderFormulas": [ { "label": "Count", "source": "This.tableData.count()" }, { "label": "Current date", "source": "Current date" } ]
Conclusion
With this new feature, 4D Write Pro empowers you to create even more dynamic and informative documents. Don’t hesitate to share your thoughts and experiences on the 4D forum!