/

Nested Tables as Tabs

The default nested_table() layout: each child table gets its own tab alongside the parent's own fields, switchable via a tab strip.

The default behavior

Unless repositioned with position(), every nested_table() call renders behind its own tab in the parent's edit form. The parent's own fields get a tab too - once at least one nested table exists, the flat field list becomes just another tab in the same strip:

$xcrud = Xcrud::get_instance();
$xcrud->table('orders');
$xcrud->route('orders');

$orderdetails = $xcrud->nested_table('Order details', 'orderNumber', 'orderdetails', 'orderNumber');
$orderdetails->columns('productCode,quantityOrdered,priceEach');

$customers = $xcrud->nested_table('Customers', 'customerNumber', 'customers', 'customerNumber');
$customers->columns('customerName,city,country');

echo $xcrud->render();

Opening an existing order's edit form here shows three tabs: the order's own fields, "Order details", and "Customers" - each nested tab a mini CRUD grid scoped to that order's rows in the corresponding child table.

default_tab() - naming the parent's own tab

By default, the parent's own fields tab is unlabeled/first once nested tabs exist alongside it. default_tab($label, $order = null) gives it a real name and, optionally, a specific position among its siblings:

public function default_tab(string $label, ?int $order = null): self
ParameterTypeDefaultDescription
$labelstringrequiredLabel for the tab holding the table's own fields
$order?intnullPosition among sibling tabs; omitted falls back to declaration order
$xcrud->default_tab('Order info');

default_tab() has no effect on a page with no nested_table() calls at all - the form stays a flat field list, with nothing to put in a tab strip.

Nesting recursively

Because nested_table() returns an XcrudNested node that itself has a nested_table() method, a nested table can have further nested tables of its own - each additional level getting the exact same tab treatment one level down. XcrudNested's own default_tab() works identically, naming that node's own row-fields tab once it has children of its own:

$orderdetails = $xcrud->nested_table('Order details', 'orderNumber', 'orderdetails', 'orderNumber');

// A further level: Products nested inside Order details' own edit form.
$products = $orderdetails->nested_table('Products', 'productCode', 'products', 'productCode');
$orderdetails->default_tab('Line item');

Editing an order detail row now shows its own two-tab strip - "Line item" (its own fields) and "Products" - nested one level inside the order's own "Order details" tab.