Dear all,
I love grocery crud and bought it already. :D
For dont display IDs as numbers in the view i use setrelation (display full name). Works fine.
I do like that feature alot but also need to use this specific field as a link in the view field.
Question: When i use callbackColumn the fullname relation stops working, How can i display the link and the fullname instead of the ID?
Following DB structrure.
Table Orders
OrderID ID INT
Productname Varchar
Price Decimal
CustomerId foreign ID INT
Table Customer
CustomerId ID INT
Firstname Varchar
Lastname Varchar
Below the code. Please help me to get it work.
<?php
include("vendor/autoload.php");
use GroceryCrud\Core\GroceryCrud;
$database = include('database.php');
$config = include('config.php');
$crud = new GroceryCrud($config, $database);
$crud->setTable('Orders');
$crud->columns(['Productname','Price','CustomerId']);
$crud->setrelation('CustomerId','Customer','{Firstname} {Lastname}');
$crud->callbackColumn('CustomerId', function ($value, $row) {
$test = "<a href='/example2/customers.php#/edit/" . $row->CustomerId."' target='frame'>".$row->CustomerId."</a>";
return $test;
});
$output = $crud->render();
if ($output->isJSONResponse) {
header('Content-Type: application/json; charset=utf-8');
echo $output->output;
exit;
}
$css_files = $output->css_files;
$js_files = $output->js_files;
$output = $output->output;
include('view.php');
Thanks for your support.
Best regards
Gregor