I have a table which I have put an image as an icon (+) <--"abrir"
, which when you click there throws me a child.rows
showing more information, what I want is that by clicking automatically I change the image or icon for (-) <--"cerrar"
and likewise if I close the previous image or icon again (+)
...
CODE
Here I show the arrangement of the data brought from mysql
for (var i = result.length -1; i >= 0; i--)
{
var rowNode = db_vigencias
.row.add([
result[i].descripcion,
'<center><img class="details-open" src="../template/images/details_open.png"></center>',<--Esta es la imagen con forma de icono (+) -->
result[i].vigencia_inicial,
result[i].vigencia_final,
])
.draw()
.node();
}
Here I say, that when I click on the icon which would be the "details-open" class, I made a validation so that in a function it shows me the data I require.
$('#db_vigencias tbody').on('click', '.details-open', function ()
{
var tr = $(this).closest('tr');
var row = db_vigencias.row( tr );
if ( row.child.isShown() ) {
// Esta fila ya está abierta - cerrarla
row.child.hide();
tr.removeClass('shown');
}
else {
// Abrir esta fila
row.child( format(row.data()) ).show();
tr.addClass('shown')//intente poner o agregar este pedazo pero no funciono//.css('background','url(' + imageUrl + ')');
}
} );
Here I show all the data I need ..
function format ( data ) {
// 'd' is the original data object for the row
return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'+
'<tr>'+
'<td><b>DESCRIPCION:</b></td>'+
'<td>'+data[0]+'</td>'+
'</tr>'+
'</table>';
}
I would appreciate your help ...
details-open.png = image icon (+) open;
details-closed.png = closed icon image (-);