Im trying to get server side processing working with concatenated columns.
I came across this this post: Datatables - Server-side processing - DB column merging
But when I use that format I get SQL errors. But I also want to insert say... a space between the fields... is this possible?
Edit:
Example:
Table init:
var customer_Table = $('#customer_Table').DataTable( {
"processing": true,
"serverSide": true,
"ajax": "php/server_processing.php",
stateSave: true,
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
'order': 2, 'asc' ]],
"columns": [{"title":"id","visible":false,"type":"html-string"},{"title":"name","visible":true,"type":"html-string"},[{"title":"address","visible":true,"type":"html-string"}
} );
Column scheme:
$columns = array(
array( 'db' => 'id', 'dt' => "id" ),
array( 'db' => 'name', 'dt' => "Name" ),
array( 'db' => "`street` . ' ' . `city` . '<br>' . `postal` . ' ' . `country`" 'dt' => "address"
)
);
Error:
{"error":"An SQL error occurred: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`id`,`name`, `JCP`, ``street` . ' ' . `city` . '<br>' . `postal` . ' ' . `country``...' at line 1"}
Judging from the error message, the processing engine is expecting a valid column reference for 'db'. Each 'db' should refer to a valid column reference in the WHERE clause, and each 'dt' contains the label to be displayed for that column.
Your reference is, according to your snippet:
"`street` . ' ' . `city` . '<br>' . `postal` . ' ' . `country`"
Which doesn't mean much to most database engines I am familiar with. Try something like this:
$columns = array(
array( 'db' => 'id', 'dt' => "id" ),
array( 'db' => 'name', 'dt' => "Name" ),
array( 'db' => "CONCAT(`street`, ' ', `city`, '<br>', `postal`, ' ', `country`)",
'dt' => "address")
);
$columns = array(
array( 'db' => 'id', 'dt' => "id" ),
array( 'db' => 'name', 'dt' => "Name" ),
array( 'db' => "CONCAT(`street`, ' ', `city`, '<br>', `postal`, ' ', `country`)",
'as' => "address",
'dt' => "address")
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.