Datagrids are one of the most powerful features in reBB's Standard Editor, allowing you to create dynamic, repeatable sections in your forms. This guide will help you understand and master datagrids to create more sophisticated forms.
A datagrid is a special component that allows users to add multiple rows of related information. Think of it as a mini-form within your form that can be repeated as many times as needed.
Common uses for datagrids include:
Adding a Datagrid to Your Form
Adding Components Inside the Datagrid
After adding a datagrid:
For example, an inventory datagrid might contain:
Configuring Datagrid Settings
Key settings to configure for your datagrid:
Datagrids require special wildcards in your templates to handle the repeating content.
Understanding Dataset Wildcards
For a datagrid with the key "inventory", you'll have two special wildcards:
{@START_inventory@}
- Marks where repeating content begins{@END_inventory@}
- Marks where repeating content endsBetween these markers, you'll use the component keys from inside your datagrid.
Basic Datagrid Template Examples
Simple List Example:
[b]Inventory:[/b]
[list]
{@START_inventory@}[*]{itemName} (Quantity: {quantity}){@END_inventory@}
[/list]
When filled out, this might generate:
[b]Inventory:[/b]
[list]
[*]Healing Potion (Quantity: 5)
[*]Rope (Quantity: 1)
[*]Torch (Quantity: 3)
[/list]
Table Example:
[table]
[tr][th]Item[/th][th]Quantity[/th][th]Description[/th][/tr]
{@START_inventory@}[tr][td]{itemName}[/td][td]{quantity}[/td][td]{description}[/td][/tr]{@END_inventory@}
[/table]
When working with datagrid templates:
Be careful with line breaks
{@START_key@}
and {@END_key@}
will be included in each iterationWatch for spacing
Template placement
Conditional Formatting Based on Row Content
You can add conditional output by structuring your template to include different formats based on values:
[b]Team Members:[/b]
{@START_team@}
[*][b]{name}[/b] - {role} (You want to display the following based on javascript: experience >= 5 ? '(Senior)' : '(Junior)')
{@END_team@}
!! This requires using JavaScript with calculated values to prepare the fields properly. !!
Datagrids become even more powerful with JavaScript:
Calculating Row Totals
For a price calculator datagrid:
// In a "subtotal" field's Calculated Value
value = row.quantity * row.unitPrice;
Calculating Grand Totals
For a field outside the datagrid:
// In a "total" field's Calculated Value
var total = 0;
if (data.orderItems && Array.isArray(data.orderItems)) {
// Note: In reBB datagrids, start from index 1 (index 0 is internal)
for (var i = 1; i < data.orderItems.length; i++) {
total += Number(data.orderItems[i].subtotal || 0);
}
}
value = total;
Validating Across Rows
To prevent duplicates:
// In Custom Validation
var isDuplicate = false;
if (data.team && Array.isArray(data.team)) {
for (var i = 1; i < data.team.length; i++) {
// Skip comparing against current row
if (i !== rowIndex && data.team[i].email === input) {
isDuplicate = true;
break;
}
}
}
valid = !isDuplicate;
Example 1: Character Skills List
Datagrid Components:
Template:
[b]Skills:[/b]
{@START_skills@}
[*][b]{skillName}[/b] - [i]{skillLevel}[/i]
{description}
{@END_skills@}
Example 2: Order Form
Datagrid Components:
JavaScript for Subtotal:
// Using a custom price lookup based on product selection
var prices = {
'product1': 10.99,
'product2': 24.99,
'product3': 5.50
};
value = (prices[row.product] || 0) * row.quantity;
Template:
[b]Order Summary:[/b]
[table]
[tr][th]Product[/th][th]Quantity[/th][th]Price[/th][/tr]
{@START_orderItems@}[tr][td]{product}[/td][td]{quantity}[/td][td]${subtotal}[/td][/tr]{@END_orderItems@}
[/table]
[b]Total:[/b] ${orderTotal}
Common Issues and Solutions
Dataset wildcards not working
{@START_key@}
and {@END_key@}
wildcards are in your templateMissing data in output
Strange formatting in output
Calculation errors
Current Limitations
As of reBB v1.3:
Workarounds
For required fields:
For validation across rows:
For complex nested structures:
By mastering datagrids, you can create sophisticated, dynamic forms that handle complex data collection scenarios while producing perfectly formatted output.