ArtiGrid
Get Started
<?php
// config/config.php
return [
'baseurl' => '/ArtiGrid/artigrid/', // url to library
'purchase_code' => 'XXX-XXX-XXX',
'db' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => 3306,
'dbname' => 'artigrid',
'user' => 'root',
'password' => '',
'charset' => 'utf8'
],
'filter' => true,
'search' => true,
'add' => true,
'refresh' => false,
'edit' => true,
'delete' => true,
'delete_multiple' => true,
];
?>
Use basic
<?php
require 'ArtiGrid.php'; // path to the Artigrid file
$grid = new ArtiGrid();
$grid->table('payments')
->template('bootstrap5')
->export(['excel','pdf','csv']) // Export buttons to Excel, PDF, and CSV
->formFields(['customerNumber','checkNumber','paymentDate', 'amount']) // show certain fields in the form
->modal();
echo $grid->render();
?>
Column Rename
<?php
$grid2 = new ArtiGrid();
$grid2->table('products')
->template('bootstrap5')
->colRename('productName','Number') // column rename
->modal();
echo $grid2->render();
?>
| id | productCode | Number | productLine | productScale | productVendor | productDescription | quantityInStock | buyPrice | MSRP | Actions | |
|---|---|---|---|---|---|---|---|---|---|---|---|
Unfiltered Raw
<?php
$grid3 = new ArtiGrid();
$grid3->table('gallery');
$grid3->template('bootstrap5');
$grid3->unset('filter', false);
$grid3->modal();
echo $grid3->render();
?>
Crud for Api
<?php
// 1. Consume the API with cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://jsonplaceholder.typicode.com/todos");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
// 2. Convert to array
$data = json_decode($response, true);
// 3. Take only the first 20 records
$data = array_slice($data, 0, 20);
// 4. Create rows for the grid with the fields you need
$rows = [];
foreach ($data as $item) {
$id = $item['id'];
$rows[] = [
'id' => $id,
'name' => "Usuario $id",
'email' => "usuario$id@mail.com",
'created_at' => date('Y-m-d', strtotime("-$id days")),
'title' => $item['title'],
'completed' => $item['completed'] ? 'Sí' : 'No'
];
}
// 5. Define grid columns
$columns = [
['name'=>'id','label'=>'ID','type'=>'number'],
['name'=>'name','label'=>'Nombre','type'=>'text'],
['name'=>'email','label'=>'Correo','type'=>'text'],
['name'=>'created_at','label'=>'Fecha','type'=>'date'],
['name'=>'title','label'=>'Título','type'=>'text'],
['name'=>'completed','label'=>'Completado','type'=>'text'],
];
// 6. Create and configure the grid
$grid4 = new ArtiGrid();
$grid4->perPage(10);
$grid4->addCustomBtn(
'btn btn-sm btn-info', // class
'ver', // action JS
'', // icon
[] // conditions
);
// 7. Prepare JSON for the grid
$jsonData = [
'columns' => $columns,
'rows' => $rows
];
// 8. Render the grid
echo $grid4->crudJson($jsonData)->render();
?>
<script>
document.addEventListener('click', function (e) {
const btn = e.target.closest('.view_action');
if (!btn) return;
alert('demo');
// example: read data-attributes
// console.log(btn.dataset.id, btn.dataset.action);
});
</script>
Fields Validations
<?php
$grid5 = new ArtiGrid();
$grid5->table('employees')
->template('bootstrap5')
->unset('filter', false)
->validation_required('lastName')
->modal();
echo $grid5->render();
?>
Callbacks
<?php
// callbacks/name_table.php // productlines.php
return [
'beforeInsert' => [
['callback' => 'insertproductlines', 'file' => 'functions.php'],
],
'afterInsert' => [
['callback' => '', 'file' => 'functions.php'],
],
'beforeUpdate' => [
['callback' => '', 'file' => 'functions.php'],
],
'beforeDelete' => [
['callback' => '', 'file' => 'functions.php'],
],
];
// file functions.php
function productlines($data){
echo "Insert stop";
die();
return $data;
}
?>
Combobox relacional
<?php
$grid6 = new ArtiGrid();
$grid6->table('customers')
->template('bootstrap5')
->unset('filter', false)
->modal();
$grid6->combobox('city','offices','officeCode','city');
echo $grid6->render();
?>
| customerNumber | customerName | contactLastName | contactFirstName | phone | addressLine1 | addressLine2 | city | state | postalCode | country | salesRepEmployeeNumber | creditLimit | avatar | photo | attach | sex | interests | Actions |
|---|
Crud whith Query
<?php
$grid7 = new ArtiGrid();
$grid7->query('SELECT * FROM products WHERE productCode = "S10_1678" ')
->template('bootstrap5')
->modal();
echo $grid7->render();
?>
Charts
<?php
$grid8 = new ArtiGrid();
$grid8->table('orderdetails')
->template('bootstrap5');
$grid8->chart_labels(
['S24_2841', 'S24_3420', 'S24_3949', 'S24_4278', 'S32_4289', 'S50_1341'],
[
[
'label' => '# of Quantity Ordered',
'data' => '#select quantityOrdered from orderdetails where id IN (60,61,62,63,64,65)',
'backgroundColor' => 'rgba(255, 99, 132, 0.2)',
'borderColor' => 'rgba(255, 99, 132, 1)',
'borderWidth' => 1
],
[
'label' => '# Price of Order',
'data' => '#select priceEach from orderdetails where id IN (60,61,62,63,64,65)',
'backgroundColor' => 'rgba(30, 23, 132, 0.2)',
'borderColor' => 'rgba(30, 23, 132, 0.2)',
'borderWidth' => 1
]
],
'pie',
[
'scales' => [
'y' => ['beginAtZero' => true]
],
'plugins' => [
'legend' => ['display' => true]
]
]
);
$grid8->chart_view(true);
echo $grid8->render();
?>
