hello Good Day!
I need to make a column with two records left me for example
if from the database get two fields, I need these two fields are in the same column, but always using server side processing
such records provider and need proof that they are in one column together
leave such an image is understood better and I'm using a translator to establish a conversation
Greetings from Argentina!
http://www.sincroniavirtual.com/table.png
In your php processing file, you want to combine the contents when you retrieve them. Can you show us your server-side code?
If you can't, what you want to do is loop through your aaData array that you are passing to dataTables. When you do so, create a new array that copies each element, and combine the 2 columns then.
For example,
[code]
$new_aaData = array();
foreach($aaData as $index => $row) {
$new_aaData[$index] = array($ow[0], $row[1] . " " . $row[2], $row[3], $row[4], $row[5], $row[6]);
}
[/code]
Here, I combined columns 2 and 3 (1 and 2 if using 0 as base index). Instead of passing $aaData to datatables, now you want to pass $new_aaData from the server-side.
You will also need to change the number of columns that dataTables thinks it is getting, since you combined two.
I had a need to combine two columns from the database as well as some text - full_name, "my text", aka_name. But I only wanted this combined when there was data in the aka_name field.
So for persons without aka_name, table cell contained "John Smith"
For persons with aka_name, table cell contained "John Smith
a.k.a.
Johnny Smyth"
And as aka_name column was being combined into name column, I could make the aka_name column invisible.
mysql also has an IF() function for conditional stuff: http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html#function_if
[code]
SELECT IF(aka != "", CONCAT(fullname, " a.k.a. ", aka), fullname) AS name FROM table;
[/code]
Hello Friends!
Thank you very much everyone for your answers but try everything and not be able to put it
I leave my code to see if anyone can help me
greetings and thank you very much!
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
ya esta solucionado !!! agrego la linea que hay que modificar por si alguien tiene el mismo problema
Saludos y muchas gracias
[code] $aColumns = array('compra_id','razon_social','compra_fc','CONCAT(compra_num_suc,"-",compra_num_com)','moneda_id','compra_coti','compra_total','compra_usuario','DATE_FORMAT(compra_fecha,"%d-%m-%Y")'); [/code]
/* * MySQL connection*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
Replies
I need to make a column with two records left me for example
if from the database get two fields, I need these two fields are in the same column, but always using server side processing
such records provider and need proof that they are in one column together
leave such an image is understood better and I'm using a translator to establish a conversation
Greetings from Argentina!
http://www.sincroniavirtual.com/table.png
If you can't, what you want to do is loop through your aaData array that you are passing to dataTables. When you do so, create a new array that copies each element, and combine the 2 columns then.
For example,
[code]
$new_aaData = array();
foreach($aaData as $index => $row) {
$new_aaData[$index] = array($ow[0], $row[1] . " " . $row[2], $row[3], $row[4], $row[5], $row[6]);
}
[/code]
Here, I combined columns 2 and 3 (1 and 2 if using 0 as base index). Instead of passing $aaData to datatables, now you want to pass $new_aaData from the server-side.
You will also need to change the number of columns that dataTables thinks it is getting, since you combined two.
Hope this helps,
Chris.
[code]
SELECT CONCAT(firstname, ' ', middleinitial, '. ', lastname) AS fullname FROM person;
[/code]
this returns 3 columns (firstname, middleinitial, lastname) as one single column
[code]
"aoColumnDefs": [
/* Name */
{ "sName": "name", "aTargets": [ 2 ] },
/* AKA_name */
{ "sName": "aka_name", "aTargets": [ 3 ] },
{ "bVisible": false, "aTargets": [ 3 ] },
/* Combine Name & AKA_name as needed */
{ "fnRender": function ( oObj ) {
if ( oObj.aData[3] != "" ) {
return oObj.aData[2] +'
a.k.a.
'+ oObj.aData[3];
}
else {
return oObj.aData[2];
}
},
"aTargets": [ 2 ]
},],
[/code]
So for persons without aka_name, table cell contained "John Smith"
For persons with aka_name, table cell contained "John Smith
a.k.a.
Johnny Smyth"
And as aka_name column was being combined into name column, I could make the aka_name column invisible.
[code]
SELECT IF(aka != "", CONCAT(fullname, " a.k.a. ", aka), fullname) AS name FROM table;
[/code]
Thank you very much everyone for your answers but try everything and not be able to put it
I leave my code to see if anyone can help me
greetings and thank you very much!
[code]<?php
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
require_once('class/class.php');
$aColumns = array('compra_id','razon_social','compra_fc','compra_num_suc','compra_num_com','moneda_id','compra_coti','compra_total','compra_usuario','compra_fecha');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "compra_id";
/* DB table to use */
$sTable = "compras";
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i[/code]
?>
Saludos y muchas gracias
[code] $aColumns = array('compra_id','razon_social','compra_fc','CONCAT(compra_num_suc,"-",compra_num_com)','moneda_id','compra_coti','compra_total','compra_usuario','DATE_FORMAT(compra_fecha,"%d-%m-%Y")'); [/code]
include( "../../db.php" );
/* Database connection information */
$gaSql['user'] = $user;
$gaSql['password'] = $pswd;
$gaSql['db'] = $bd;
$gaSql['server'] = $localhost;
/* * MySQL connection*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/* * Paging */
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ){
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* ARREGLO PARA LAS BUSQUEDAS Y ORDERBY*/
$aColumns = array( 'alumnos.id','alumnos.matricula','alumnos.curp','alumnos.nombre','alumnos.nivel',"CONCAT_WS(',',alumnos.grupo,alumnos.anio)",'colegiatura.cuota',
"CONCAT_WS(',',padres.padre,padres.madre)","CONCAT_WS(',',padres.correo_p,padres.correo_m)", 'padres.rfc' );
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/** Ordering*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) ){
$sOrder = "ORDER BY ";
for ( $i=0 ; $i $iFilteredTotal,
"aaData" => array()
);
$nivel=array("1"=>"Preescolar","2"=>"Primaria","3"=>"Secundaria");
/* ARREGLO PARA USAR SOLO ABAJO */
$aColumnsX = array( 'id','matricula','curp','nombre','nivel','gruposx','cuota','padresn','padrese', 'rfc' );
while ( $aRow = mysql_fetch_array( $rResult ) ){
$row = array();
for ( $i=0 ; $i
Allan