'Sort ServerSide DataTable on calculated / formatted value that is not a column in the DB

I've been using Laravel Datatables for awhile in some of the Laravel applications and I really love that, and probably using a fraction of the features. I also have some legacy PHP applications that can use Composer and it is an MVC framework, but not Laravel.

DataTables Server Side Example, and that provides some of the same features, with the important exception that I can do something like this with the Laravel version:

...
$query = 'Some complex query with JOINS, WHERES, ETC";
$data = DB::connection('mysql2')->select($query, $where_clause_params);
return Datatables::of($data)
->addIndexColumn()
->editColumn('patient_lname', function ($row) {
     return $row->patient_lname.'<br>Sex:  '.$row->patient_sex.'<br>DOB:  '.$row->patient_birth_date;
 })
 .....

whereas the Datatables uses something like this:

 . . .
 $table = 'exams';
  $primaryKey = 'requested_procedure_id';
 $columns = array(
    array(
        'db'=> 'requested_procedure_id',
        'dt'=> 'requested_procedure_id'),
     array(
        'db' => 'exam_name',
        'dt' => 'exam_name' ),
    . . .

The Laravel version seems to have many more capabiities maybe because it leverages Eloquent.

It does seem like it might be possible to to extend the capabilities of the vanilla Datatables version by creating a MySQL View that has columns with all of the values that I want to display in the datatable, such that I can search and sort on that value.

Just wondering if you can do something like that with DataTables and Views ?

This SO post might be relevant: Datatables.net's Server-Side Processing (SSP) with PHP

I mostly want to tidy-up the legacy app and any new work will likely use Laravel, which has more features. Just not sure what might be the best approach.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source