5.2: Creating Sub-Tables โ
Ready to see sub-tables in action? In this tutorial, you'll build a real order processing system that automatically handles multiple items per order. By the end, you'll have orders that process each item, calculate line totals, and sum everything upโall automatically!
What we're building: An order processing system where:
- ๐ Each order can have multiple products
- ๐ Each product gets its own row for processing
- ๐ฐ Line totals calculate automatically (quantity ร price)
- โจ The grand total rolls up from all items
๐ก What You'll Learn
By the end of this section, you'll know how to:
- โ Start with order data containing multiple items
- โ Convert item lists into sub-tables
- โ Add calculations to individual items
- โ Aggregate results back to the parent order
- โ See your first complete order processing flow!
5.2.1: The Scenario - Processing Orders โ
Imagine: You run an online store. Orders come in with multiple products, and you need to:
- Check what items are in each order
- Calculate the price for each item (quantity ร unit price)
- Calculate the total order amount
The challenge: How do you handle orders with 1 item? 5 items? 50 items? You need a flexible system that processes each item individually.
The solution: Sub-tables! Let's build it step-by-step.
๐ก ๐ก Real-World Context
This is exactly how e-commerce systems work:
- Amazon processes each item in your cart separately
- Each item has its own stock check, pricing, and shipping calculation
- The order total is the sum of all item totals
- Sub-tables make this pattern simple!
5.2.2: Step 1 - Start with Your Data โ
First, you need a table with orders. Each order will have a list of items.
Let's create an "Orders" table:
- Click "Create New Table"
- Name it "Orders"
- Add these columns:
- Order ID (Manual Input - Text)
- Customer (Manual Input - Text)
- Date (Manual Input - Date)
Add a test row:
| Order ID | Customer | Date |
|---|---|---|
| #1001 | John | Oct 24 |
Now, add the items column:
- Click "Add Column"
- Choose "Manual Input - JSON" (for now, we'll manually add item data)
- Name it "Items"
For the test row, enter this JSON data:
[
{"product": "Laptop", "quantity": 1, "price": 999},
{"product": "Mouse", "quantity": 2, "price": 25},
{"product": "Keyboard", "quantity": 1, "price": 79}
]What you'll see:
When adding a column, select the Add Row type.
- โข Column Name: order_items
- โข Type: Add Row (creates children in another taible)
- โข Target Taible: Order Line Items
The "Items" column now shows "[3 Entries]" with a badgeโthis is collection data ready to become a sub-table!
๐ก ๐ฏ You're Ready!
You now have order data with multiple items. In a real system, this data would come from a webhook, API, or form submission. For learning, we're entering it manually.
5.2.3: Step 2 - Convert to Sub-Table โ
Now comes the magic! Let's turn that list of items into a proper sub-table.
Here's how:
- Hover over the "Items" column header
- Click the three-dot menu (โฎ) on the right side
- Select "Convert into taible" from the dropdown
Step-by-step:
- Hover your mouse over the "Line Items" column header
- Two icons appear on the right side
- Click the three-dot menu (โฎ) - highlighted in yellow above
- A dropdown menu will open with options
A dialog appears with conversion options:
Convert into taible
The ID property is used to check the existence of entries in the taible we'll create.
Configure the conversion:
ID Property: Select "product"
- This uniquely identifies each item
- Helps Taibles track which items exist
Destructure toggle: Turn it ON โ
- This creates separate columns for each property
- You'll get columns for: product, quantity, price
Click "Convert"
What happens:
- Taibles creates a new sub-table
- Each item becomes its own row in the sub-table
- You can now add columns that process each item!
Converting to Sub-Taible...
Please wait while we process your data
About 30 seconds remaining...
๐ก Understanding Destructuring
With destructuring ON:
- Each property (product, quantity, price) gets its own column
- Easy to reference: just use the column name
- Perfect for structured data
With destructuring OFF:
- Items stored as JSON objects
- Need to extract fields manually
- Use when data structure varies
For our tutorial, keep it ONโit's much easier to work with!
5.2.4: Step 3 - See the Sub-Table โ
After conversion, your "Items" column changes appearance. Let's explore!
In the Orders table, you now see:
The system creates or links to a child taible:
Click the arrow (โ) next to "[3 items]" to open the sub-table view.
You'll see the sub-table:
Click to Open Child Taible
Interactive example component
What you're looking at:
- Three rows (one for each item)
- Three columns (product, quantity, price)
- Each item is now processable individually!
๐ก ๐ You Did It!
You just created your first sub-table! The order items are now separate rows that can be processed independently. Next, we'll add calculations!
5.2.5: Step 4 - Add Actions to Sub-Table โ
Now for the fun partโlet's calculate the line total for each item!
While viewing the sub-table:
- Click "Add Column" (in the sub-table, not the main table)
- Choose "Custom Code" (we'll write a simple formula)
- Name it "Line Total"
In the code editor, enter:
return quantity * priceConfigure dependencies: 4. Add "quantity" as a dependency 5. Add "price" as a dependency
Save the column!
What you'll see:
Line Total Calculation
Interactive example component
Magic moment: Each row now calculates its line total automatically!
- Laptop: 1 ร $999 = $999
- Mouse: 2 ร $25 = $50
- Keyboard: 1 ร $79 = $79
๐ก ๐ก The Power of Sub-Tables
Notice what just happened:
- You added ONE column
- It runs for EVERY item automatically
- Each item gets its own calculation
- No loops, no complex codeโjust works!
This is the magic of sub-tables: actions run for each child row automatically.
5.2.6: Step 5 - Gather Results Back โ
Now let's calculate the total order amount by summing all line totals!
Navigate back to the parent Orders table:
- Click the "โ Orders" breadcrumb at the top
- Or click outside the sub-table view
Add a new column in the main Orders table:
- Click "Add Column" (in the Orders table)
- Choose "Custom Code"
- Name it "Total Amount"
In the code editor, enter:
def items = items_destructured // Reference the sub-table
def total = 0
items.each { item ->
total += item.line_total
}
return totalConfigure dependencies: 4. Add "items_destructured" as a dependency
- This is the sub-table column (after conversion)
Save the column!
What you'll see:
| Order ID | Customer | Date | Order Items |
|---|---|---|---|
| #1001 | John | Oct 24 | 3 Entries |
The grand total appears: $999 + $50 + $79 = $1,128 โจ
๐ก ๐ Complete System Working!
You just built a complete order processing system:
- โ Orders have multiple items
- โ Each item calculates its line total
- โ The order total sums all line totals
- โ Everything updates automatically!
5.2.7: See the Complete Flow โ
Let's see what you built in action:
Automation Flow
Interactive example component
The data flows like this:
Parent Level (Orders Table):
- Order ID, Customer, Date โ entered manually
- Items column โ contains the sub-table
Child Level (Items Sub-Table):
- Product, Quantity, Price โ from the items data
- Line Total โ calculated automatically (quantity ร price)
Back to Parent:
- Total Amount โ sums all Line Total values
Add another order to test it:
- Go back to the Orders table
- Click "+ Add Row"
- Enter Order ID, Customer, Date
- In Items, enter:
[
{"product": "Monitor", "quantity": 2, "price": 299},
{"product": "Cable", "quantity": 3, "price": 15}
]- Watch the magic happen!
The new order automatically:
- Creates 2 item rows in the sub-table
- Calculates line totals: Monitor ($598), Cable ($45)
- Calculates order total: $643
๐ก ๐ก This Works at Scale
The same system works whether an order has:
- 1 item โ 1 row in sub-table
- 10 items โ 10 rows in sub-table
- 100 items โ 100 rows in sub-table
The logic never changes! Sub-tables scale automatically.
5.2.8: What You Can Do Next โ
Now that you have a working sub-table, you can extend it in countless ways:
In the Items sub-table, add columns to:
- ๐ข Look up product details (weight, category, supplier)
- ๐ฆ Check stock availability
- ๐ Calculate shipping costs per item
- ๐ท๏ธ Apply discounts or promotions
- ๐ Track item status (packed, shipped, delivered)
In the Orders table, add columns to:
- ๐ณ Calculate tax (based on total amount)
- ๐ Calculate shipping (based on item weights from sub-table)
- ๐ง Send order confirmation emails
- ๐ Update inventory levels
- ๐ต Process payments
๐ก ๐ฏ You're a Sub-Table Pro!
You now know:
- โ How to start with collection data
- โ How to convert it to a sub-table
- โ How to add calculations to items
- โ How to aggregate results back to parent
- โ The power of automatic item processing!
5.2.9: Quick Review โ
Let's recap the key steps for creating sub-tables:
Step 1: Start with Data
- Table with a column containing collection data (arrays)
- Shows as
[X Entries]with a badge
Step 2: Convert to Sub-Table
- Hover over column header โ three-dot menu
- Select "Convert into taible"
- Choose ID property and destructure options
Step 3: Explore Sub-Table
- Click arrow to open sub-table view
- See items as individual rows
Step 4: Add Item-Level Columns
- Add columns to process each item
- They run automatically for every item
Step 5: Aggregate to Parent
- Add columns in parent table
- Sum, count, or combine child data
That's it! This pattern works for any one-to-many relationship.
What You've Learned โ
Congratulations! You just built your first working sub-table system:
๐ Created an order processing system with multiple items per order
๐ Converted collection data into a structured sub-table
๐ฐ Added item-level calculations that run for each item automatically
โจ Aggregated results back to the parent order
๐ฏ Saw the complete data flow from items to totals
This fundamental pattern applies to countless scenarios:
- Orders โ Line items
- Customers โ Purchase history
- Projects โ Tasks
- Emails โ Attachments
- Campaigns โ Recipients
You now have a powerful tool for handling any one-to-many relationship!
๐ก ๐ Coming Up Next
In the next section (5.3: More Examples), you'll see sub-tables in action for:
- Email attachments processing
- Customer conversation history
- Project task management
- Report generation
Each example shows different ways to use the same powerful pattern!
Previous: 5.1 Understanding CollectionsNext: 5.3 More Examples