1
I have the following checkboxes:
<div class="row smart-form">
<section class="col col-1.5">
<label class="toggle">
<input type="checkbox" name="checkbox-toggle" rel="Natureza" value="Produtos">
<i data-swchon-text="ON" data-swchoff-text="OFF"></i>
Produtos</label>
</section>
<section class="col col-1.5">
<label class="toggle">
<input type="checkbox" name="checkbox-toggle" rel="Natureza" value="Produtos Auto-Utilizados">
<i data-swchon-text="ON" data-swchoff-text="OFF"></i>
Produtos Auto-Utilizados</label>
</section>
</div>
I have this table that retrieves data from the comic book:
<table id="datatable_fixed_column" class="table table-striped table-bordered" width="100%">
<thead>
<tr class="first">
<th>Código</th>
<th>Nome</th>
<th>Descrição</th>
<th>Designação Comercial</th>
<th>Unidades</th>
<th>IVA %</th>
<th>Stock</th>
<th>Natureza</th>
</tr>
</thead>
<tbody>
@for(art <- artigos) {
<tr>
<td>@art.getId()</td>
<td>@art.getNome()</td>
<td>@art.getDescricao()</td>
<td>@art.getDesignacaoComercial()</td>
<td>@art.getIva().getValor()</td>
<td>@art.getStockAtual()</td>
@for(nat <- art.getDesignacoes()) {
<td> @nat.getGestaoComparativa().getNatureza().getDescricao()</td>
}
</tr>
}
</tbody>
</table>
Javascript
$("input:checkbox").click(function () {
var showAll = true;
$('tr').not('.first').hide();
$('input[type=checkbox]').each(function () {
if ($(this)[0].checked) {
showAll = false;
var status = $(this).attr('rel');
console.log("STATUS: " + status);
var value = $(this).val();
console.log("VALUE: " + value);
$('td.' + status + '[rel="' + value + '"]').parent('tr').show();
}
});
if(showAll){
$('tr').show();
}
});
I still don’t understand why it’s not working for me. I don’t really understand what the "rel= "
. I tried to adapt the code from this source.
Every time I hit a checkbox, all my data is gone. I would like someone to help me interpret the source code to understand where you get the names that are filtered and the columns.
PS: I only need to filter the data from the Nature column.
Is this import: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> necessary? With this import, running the page shows these errors or warnings: Uncaught Typeerror: Cannot read Property 'on' of Undefined app.min.js:1 Uncaught Typeerror: Undefined is not a Function
– Hugo Machado
Yes @Hugomachado, this is a function
JQuery
, just having the libraryJQuery
instantiated in your project.– MarceloBoni
Thanks for your help, it was very explicit. Only the import of the Jquery library seems to hinder the work. first changes the design of the table I have, and these warnings appear to me that I showed you in the previous comment, and when you click on the checkboxes it does nothing, without that matter, at least when you click on the checkboxes the data disappeared and appeared.
– Hugo Machado
So, before your own
checkBox
you must put the following:rel="natureza" value="valorDaPesquisa"
andrel="valorDaPesquisa" value="Auto"
. Second, this function you passed as an example is native to Jquery, without the library, there is no way the function works ;/– MarceloBoni
It is already working, the "value" I put is that differed from what was presented in the table, hence it is always deserpe. Thank you @Marcelo Bonifazio !
– Hugo Machado