Skip to content

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:

  1. Check what items are in each order
  2. Calculate the price for each item (quantity ร— unit price)
  3. 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:

  1. Click "Create New Table"
  2. Name it "Orders"
  3. Add these columns:
    • Order ID (Manual Input - Text)
    • Customer (Manual Input - Text)
    • Date (Manual Input - Date)

Add a test row:

Order IDCustomerDate
#1001JohnOct 24

Now, add the items column:

  1. Click "Add Column"
  2. Choose "Manual Input - JSON" (for now, we'll manually add item data)
  3. Name it "Items"

For the test row, enter this JSON data:

json
[
  {"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 Configuration:
  • โ€ข 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:

  1. Hover over the "Items" column header
  2. Click the three-dot menu (โ‹ฎ) on the right side
  3. Select "Convert into taible" from the dropdown
Line Items

Step-by-step:

  1. Hover your mouse over the "Line Items" column header
  2. Two icons appear on the right side
  3. Click the three-dot menu (โ‹ฎ) - highlighted in yellow above
  4. 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:

  1. ID Property: Select "product"

    • This uniquely identifies each item
    • Helps Taibles track which items exist
  2. Destructure toggle: Turn it ON โœ…

    • This creates separate columns for each property
    • You'll get columns for: product, quantity, price
  3. 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

Child taible created
Columns configured
Converting rows... (23/47)
Linking parent-child relationships

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:

Order Line Items Taible (created)
(empty - no rows yet)

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:

  1. Click "Add Column" (in the sub-table, not the main table)
  2. Choose "Custom Code" (we'll write a simple formula)
  3. Name it "Line Total"

In the code editor, enter:

groovy
return quantity * price

Configure 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:

  1. Click "Add Column" (in the Orders table)
  2. Choose "Custom Code"
  3. Name it "Total Amount"

In the code editor, enter:

groovy
def items = items_destructured // Reference the sub-table
def total = 0

items.each { item ->
  total += item.line_total
}

return total

Configure dependencies: 4. Add "items_destructured" as a dependency

  • This is the sub-table column (after conversion)

Save the column!

What you'll see:

Order IDCustomerDateOrder Items
#1001JohnOct 24
3 Entries
Hover over the cell to see the arrow button, then click to view child items

The grand total appears: $999 + $50 + $79 = $1,128 โœจ

๐Ÿ’ก ๐ŸŽ‰ Complete System Working!

You just built a complete order processing system:

  1. โœ… Orders have multiple items
  2. โœ… Each item calculates its line total
  3. โœ… The order total sums all line totals
  4. โœ… 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:

  1. Go back to the Orders table
  2. Click "+ Add Row"
  3. Enter Order ID, Customer, Date
  4. In Items, enter:
json
[
  {"product": "Monitor", "quantity": 2, "price": 299},
  {"product": "Cable", "quantity": 3, "price": 15}
]
  1. 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

Built with VitePress