I have the following code:
JS:
function declararDataTable()
{
var id_temporada = $("#id_temporadaVal").val();
var id_equipo = $("#id_equipoVal").val();
tabla_jugadores = $('#jugadores').dataTable({
"oLanguage": {
"sLengthMenu": "Mostrar _MENU_ jugadores por página",
"sZeroRecords": "No existen jugadores",
"sInfo": "Mostrando _START_ a _END_ de _TOTAL_ jugadores",
"sInfoEmpty": "Mostrando 0 a 0 de 0 jugadores",
"sInfoFiltered": "(Encontrados de _MAX_ jugadores)"
},
"aoColumns": [{"sWidth":"20%"},{"sWidth":"10%"},{"sWidth":"10%"}],
"bProcessing": true,
"sAjaxSource": '../includes/acciones/compilacion/get_jugadores_equipos_json.php',
"fnServerParams": function ( aoData ) {
aoData.push({ "name": "id_temporada", "value": id_temporada });
aoData.push({ "name": "id_equipo", "value": id_equipo });
},
"iDisplayLength": 25
});
}
PHP:
<?php
include_once("../../clases/class.Jugador.php");
extract($_GET);
# id_temporada
# id_equipo
$jugadores = Jugador::getLista($id_equipo, $id_temporada);
$json = array();
if(is_array($jugadores))
{
foreach($jugadores as $jugador)
{
$temp = array();
array_push($temp, $jugador["nombre"]." ".$jugador['apellido_paterno']." ".$jugador["apellido_materno"]);
$link = "<a href='javascript:visuaModal(".$jugador['id_jugador'].");'>
<img src='../img/editar.png' width='30' height='30'></a>";
array_push($temp, $link);
$link2 = "<a href='javascript:bajas(".$jugador['id_jugador'].");'>
<img src='../img/eliminar.png' width='30' height='30'></a>";
array_push($temp, $link2);
array_push($json, $temp);
}
}
echo json_encode(array("aaData" => $json));
?>
I explain with the JavaScript function declararDataTable
what I do is send certain parameters to php with which I am going to obtain the information to display in the DataTable, that same function receives from php a JSON which contains the information to print in the DataTable, the inconvenience that I am having is that I need to paint the rows but this will depend on a value, for example:
<?php
foreach($jugadores as $jugador)
{
$temp = array();
$no_equipos = Jugador::getTotalEquipos($jugador['id_jugador'], $id_temporada);
if($no_equipos == 2)
// Se pintaria la fila a color amarillo
else
// La fila no se pinta
array_push($temp, $jugador["nombre"]." ".$jugador['apellido_paterno']." ".$jugador["apellido_materno"]);
$link = "<a href='javascript:visuaModal(".$jugador['id_jugador'].");'>
<img src='../img/editar.png' width='30' height='30'></a>";
array_push($temp, $link);
$link2 = "<a href='javascript:bajas(".$jugador['id_jugador'].");'>
<img src='../img/eliminar.png' width='30' height='30'></a>";
array_push($temp, $link2);
array_push($json, $temp);
}
?>
How could I solve this??
You could do this by adding a variable
style
and adding abackground-color
to it so that it defaults totransparent
.I hope it helps you, greetings.