ArtiGrid
v1.6

CRUD with Query

ArtiGrid allows you to build a CRUD interface using custom SQL queries through the query() method.

This provides full control over the data source, allowing you to filter, join, or transform data directly at the query level instead of relying on a fixed table.

It is especially useful for advanced scenarios where you need specific datasets or more complex data structures.

When using custom queries, ArtiGrid cannot automatically determine which table should be used for write operations (insert, update, delete). For this reason, you must explicitly define it using the editable() method.

The editable() method receives the table name, enabling ArtiGrid to handle all CRUD operations such as add, view, edit, and delete, even when the data is loaded from a custom query.

Note: When using custom queries with joins, make sure the table defined in editable() matches the primary table you intend to update.


<?php
$grid = new ArtiGrid();
$table = 'products';

$grid->query("SELECT * FROM $table WHERE productCode = 'S32_2206'")
    ->editable($table)
    ->template('bootstrap5')
    ->formFields([
        'productCode',
        'productName'
    ])
    ->crudCol([
        'id',
        'productCode',
        'productName'
    ])
    ->required(false)
    ->validation_required('productCode')
    ->modal();

echo $grid->render();
?>
id productCode productName Actions