Server-Side with Joins.

Server-Side with Joins.

AtharosAtharos Posts: 1Questions: 0Answers: 0

Hi! I'm fairly new to DataTables, but I'm already in love. Congratulations to the developers!
I've seen a couple of threads of people asking how to use server-side processing with JOINS. Though it is probably not the best way, it's the way I managed to make it work, and so far, so good :D!
Anyway, this is an alteration of the original ssp.class.php. It uses Aliases provided by the table list Array when needed, so no functionality is lost.

https://drive.google.com/file/d/0B08H3fQ2RNJMLUFKSmJvSlVNTTA/view?usp=sharing

$columns = array(
array( 'db' => 'Protocolos.ID', 'dt' => 'Protocolo', 'Alias' => 'Identificador' ),
array( 'db' => "CONCAT(Medicos.Apellido, ', ', Medicos.Nombre)", 'dt' => 'Medico', 'Alias' => 'Medico' ),
array( 'db' => "CONCAT(Pacientes.Apellido, ', ', Pacientes.Nombre)", 'dt' => 'Paciente', 'Alias' => 'AyN' ),
array( 'db' => 'Localizacion', 'dt' => 'Localizacion', 'Alias' => 'Localizacion' ),
array( 'db' => "SUBSTRING(Protocolos.InformePrincipal,1,55)", 'dt' => 'Diag', 'Alias' => 'InformePrin' ),
array( 'db' => "DATE_FORMAT(Protocolos.FechaBiopsia,'%m/%d/%Y')", 'dt' => 'Ingreso', 'Alias' => 'FechaIngresoBiopsia' )
);

$join = " Inner Join Pacientes On Pacientes.ID = protocolos.PacienteID Inner Join Medicos On Protocolos.MedicoID = Medicos.ID ";

They $join variable will, as the name suggest, contain the JOINS. Other than that, you should just add the column "Alias" to the $columns array.

Finally, you just call further functions like this.

require( 'ssp.class1.php' );

echo json_encode(
SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns, $join )
);

Well, probably not genius, but I got a lot of help from this forums, and wanted to give a little something back. Perhaps someone will find it useful!

Replies

  • wong89wong89 Posts: 3Questions: 0Answers: 0

    where clause not work on function simple

This discussion has been closed.