Skip to content
Advertisement

How to editColumn on a relationship column in Laravel Yajra DataTables

I’m using Laravel 6 with Yajra Datatable.

I’m creating a “SessionDataTable” on a Session Model. This model has a Patient relationship

JavaScript

Here is the Column Definition :

JavaScript

here is the Column edit :

JavaScript

The problem is this “editColumn(‘patient_id’)” is ignored. I have a patient_id column in the datatable, but it contains only the firstname, as defined in the column definition. The editColumn(‘name’) is completely ignored and doesn’t appears in the datatable.

The goal is to display the patient fullname in the DT Cell, which is the name attribute of the Patient Model. The name attribute is not a db field, it’s a laravel attribute which concat firstname and lastname db field

JavaScript

I’m not even asking for search or ordering for now, I can order and search only on lastname, but I really need to display the fullname. Why is the editColumn being ignored ?

Here is the Datatable Query Definition :

JavaScript

Advertisement

Answer

Ok, I found myself :

If you are using the ->data() in the column definition this way :

JavaScript

You need to use the same name in the editColumn as the one in the data : ->data(), in may case : patient.firstname

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement