I have a php file with a table getted from dataTable.net
I load my table and content with this code:
<div class="table-responsive">
<div class="panel-responsive">
<div class="panel-heading" align="center"><h3>Usuarios</h3></div>
<table id="example" class="display" cellspacing="0" width="100%">
<?php
//require_once('funciones.php');
//conectar('localhost', 'root', '', 'agroapp');
$result = mysql_query("SELECT * FROM usuario WHERE username <> 'admin'");
if ($row = mysql_fetch_array($result)){
?>
<thead>
<tr>
<th>Username</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Username</th>
</tr>
</tfoot>
<tbody>
<?php
do {
$titulo=$row['nombre'];
$post = $row['username'];
$rol = $row['rol'];
$idUser = $row['idUsuario'];
echo "<tr > \n";
//if($row["username"]!="admin"){
//echo "<td > </td> \n";
echo "<td ><img src= ".$row["ruta"]." height='30' width='30 class=profile-photo img-circle'> ".$row["username"]." </td> \n";
echo "</tr> \n";
//}
} while ($row = mysql_fetch_array($result));
//echo "</tbody></table> \n";
} else {
echo '<h5 align="center">¡ No tiene empleados añadidos! </h5>';
}
?>
</tbody>
</table>
</div>
</div>
I'm add a selected when I click into a row with the next code, but I can't get the value username, because I get in the php file called from jquery a [object object] or undefined. This is getted when use :
myFunction(table.row('.selected').value);
And I try also use table.row('.selected').eq(0).data('username'), and value('username')... But I can't get the value.
<script>
$(document).ready(function() {
var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'tr', function () {
if ( $(this).hasClass('selected') ) {
$(this).removeClass('selected');
}
else {
table.$('tr.selected').removeClass('selected');
$(this).addClass('selected');
}
} );
$('#button').click( function () {
myFunction(table.row('.selected').eq(0).data('username')); //Here I'm trying get the value
table.row('.selected').remove().draw( false );
} );
} );
function myFunction(val) {
var getted = val;
$.ajax({
data: 'empleado=' + getted,
url: 'updateEmpleado.php',
method: 'POST', // or GET
success: function(msg) {
//alert(msg);
location.reload();
}
});
}
</script>
How can I get the value of row selected? Thanks!