Merge SQL COlumns for Use in Server Side Processing

Merge SQL COlumns for Use in Server Side Processing

anderew_markanderew_mark Posts: 1Questions: 1Answers: 0
edited October 2019 in Free community support

I have searched quite extensively for this and though there are other similar questions, I can't seem to find one with an accepted answer. Here Goes, using php/msql.

I have a mysql table, in that table there are a number of columns, two of them, record_name and record_surname.

Now, if I follow the code in the php server-side example, like so...

$columns = array(
array( 'db' => 'record_name', 'dt' => 0 ),
array( 'db' => 'record_surname', 'dt' => 1 ),
array( 'db' => 'visibility', 'dt' => 2 ),
);

I make a call...

$('#datatable').DataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": "path/to/the/above/in/server/side/file.php"
} );

This outputs to the browser a table with three columns and it is rendered properly. HOWEVER, I wish to merge record_name and record_surname so that it is considered as one column. In mysql I would normally do something like...

CONCAT(record_name,' ',record_surname) AS full_name, my thinking is then, I could have something like this...

$columns = array(
array( 'db' => 'full_name', 'dt' => 0 ), // < is it possible here to reference a concat function output
array( 'db' => 'visibility', 'dt' => 1 ),
);

However, I have tried numerous ways, including those suggested in answers to those asking a similar question, but I cannot get this logic to work.

Is it possible to do this, does anyone have a hint or tip.

Thanks in advance for any help.

Answers

  • allanallan Posts: 63,538Questions: 1Answers: 10,476 Site admin

    Don't do it in SQL, rather do it using a renderer.

    This Editor example shows a renderer being used for exactly that for the Name column.

    If you did want to do it in SQL you'd probably be bast creating a VIEW and having the SSP class read from there. Or you could modify the SSP class to support CONCAT if you preferred.

    Allan

This discussion has been closed.