I need to go through a table to see if an element already exists in the first column.
Table:
<table id="tabela-resultado" class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th>Nome</th>
<th>Ativo</th>
<th class="text-center">Ação</th>
</tr>
</thead>
<tbody>
<?php if(count($records)) { ?>
<?php foreach($records as $record) { ?>
<tr data-id="<?php echo $record->id; ?>">
<td>
<?php echo $record->nome; ?>
</td>
<td>
<?php
if ($record->ativo == 1) {
echo "SIM";
} else if($record->ativo == 0){
echo "NÂO";
}
?>
</td>
<td>
<?php echo anchor("gurpoProduto/excluir", "<i class='glyphicon glyphicon-trash'></i> Exlcuir", ['class' => 'btn btn-danger btn-block', 'name' => 'delete']); ?>
</td>
</tr>
<?php
}
}
?>
</tbody>
</table>
What I've tried:
function verificar_existencia(nome) {
var table = $("#tabela-resultado table tbody");
var nomeTabela = '';
table.find('tr').each(function(nome) {
var $tds = $(this).find('td'),
nomeTabela = $tds.eq(0).text()
});
if (trim(nome.toUpperCase()) === trim(nomeTabela.toUpperCase())) {
toastr.success("Este grupo já existe!", "Aviso");
//return false;
}
}
When I call the function verifica_existencia(nome)
, it does not return me toastr.success("Este grupo já existe!", "Aviso");
when I insert an element that already exists.