ArtiGrid
v1.7

Nested Table

Nested tables in ArtiGrid allow you to build powerful multi-level relational data interfaces directly from PHP with minimal configuration. Using parent and child relationships, you can display expandable grids inside other grids, making it easy to manage complex database structures such as orders, order details, products, product lines, customers, invoices, payments, or any hierarchical data model. In this example, the main orders table contains two independent nested grids: Order Details and Customers. The Order Details grid also contains another nested grid for Products, which itself contains a fourth-level nested grid for Product Lines. This demonstrates how ArtiGrid supports deeply nested CRUD structures without requiring manual AJAX requests, custom JavaScript logic, frontend frameworks, or complex routing systems. Each nested grid can have its own independent configuration including actions, pagination, templates, modal behavior, visible columns, form fields, bulk actions, search tools, validation rules, and conditional actions. You can even apply custom action conditions, as shown in this example where editing is only enabled for specific product codes. With nested tables, ArtiGrid automatically handles:

This allows developers to create enterprise-level administrative panels and relational data management systems with dramatically less code while maintaining full flexibility and scalability.


<?php
    $grid = new ArtiGrid();
    $grid->table('orders');
    $grid->template('bootstrap5');
    $grid->unset("add", true);
    $grid->perPage(5);
    //$grid->modal();
    $grid->required(false);
    $grid->validation_required("customerNumber");
    // Level 2 — orderdetails
    $grid->nestedTable("Order details", "orderNumber", "orderdetails", "orderNumber", [
        "actions" => [
            "add" => true, 
            "edit" => true, 
            "delete" => true,
            "view" => true, 
            "search" => true, 
            "refresh" => true,
            "delete_multiple" => true,
            "edit_multiple" => true
        ],
        "buttonsArrange" => true,
        'actionConditions' => [
        'edit' => [
                [
                    'field' => 'productCode',
                    'operator' => '!=',
                    'value' => 'S18_2325'
                ]
            ]
        ],
        "requiredFields" => ["productCode", "quantityOrdered", "priceEach"],
        "inlineEditEnabled" => false,
        "columns"    => ['productCode', 'quantityOrdered', 'priceEach'],
        "formFields" => ['productCode', 'quantityOrdered', 'priceEach'],
        "perPage"    => 5,
        "template"   => "bootstrap5",
        "useModal"   => false,

        // Level 3 — products (child of orderdetails)
        "nestedGrids" => [
            [
                'label'      => 'Products',
                'parentKey'  => 'productCode',
                'childTable' => 'products',
                'childKey'   => 'productCode',
                'config'     => [
                    "actions"  => [
                        "add" => true, 
                        "edit" => true,
                        "delete" => false,
                        "view" => true,
                        "delete_multiple" => true,
                        "edit_multiple" => true
                    ],
                    "buttonsArrange" => false,
                    "inlineEditEnabled" => false,
                    //"insertFormTemplate" => "<h1>gfff</h1>",
                    "requiredFields" => ['productCode','productName', 'productLine', 'quantityInStock'],
                    "columns"  => ['productCode','productName', 'productLine', 'quantityInStock'],
                    "formFields" => ['productCode', 'productName', 'productLine', 'quantityInStock'],
                    "perPage"  => 5,
                    "template"   => "bootstrap5",
                    "useModal"   => true
                ]
            ]
        ]
    ]);

    // Level 2 — customers (second child of orders, independent)
    $grid->nestedTable("Customers", "orderNumber", "customers", "orderNumber", [
        "actions" => [
            "add" => true, 
            "edit" => true, 
            "delete" => true,
            "view" => true,
            "search" => true,
            "delete_multiple" => true,
            "edit_multiple" => true
        ],
        "buttonsArrange" => false,
        "inlineEditEnabled" => false,
        "requiredFields" => ['customerName', 'city', 'country', 'customerNumber'],
        "columns"    => ['customerNumber', 'customerName', 'city', 'country'],
        "formFields" => ['customerName', 'city', 'country'],
        "perPage"    => 5,
        "template"   => "bootstrap5",
        "useModal"   => true
    ]);
    echo $grid->render();
?>
orderNumber orderDate requiredDate shippedDate status comments customerNumber Actions