0
Good morning, what I am trying to do is the following, I have two fields with inputs, 1 for Seller and another for Customer.
Below these fields I have my table that loads the data that comes from the database with all the object data, with name, date, type and value, and whether it is revised or not.
What I’m trying to do is filter the data that comes from the table, if I type in the Seller’s input text or type in the Customer’s input text, and click the Enter button on the keyboard, to view the database data through the name of the Customer or the name of the Seller I have entered in any of the inputs.
I’m starting with Jquery, and I tried to do it this way, I’ll leave the code snippet for some help.
From now on, thank you!
My form:
<div id="Filtros" class="accordion-body collapse in">
<div class="accordion-inner">
<div class="well">
<form action="@Url.Action("Filtros")" method="POST" id="formFiltros">
<fieldset>
<div class="control-group">
<div class="row-fluid">
<div class="span6">
@Html.LabelFor(x => x.IdFornecedor, "Vendedor")
<div class="controls">
@Html.TextBox("FornecedorAutoComplete", "", new { placeholder = "Digite um vendedor..." })
@Html.HiddenFor(x => x.IdFornecedor)
</div>
</div>
<div class="span6">
@Html.LabelFor(x => x.IdGrupoEmpresa, "Adquirente")
<div class="controls">
@Html.TextBox("GrupoEmpresaAutoComplete", "", new { placeholder = "Digite um adquirente(nome ou cnpj)..." })
@Html.HiddenFor(x => x.IdGrupoEmpresa)
</div>
</div>
</div>
</div>
</fieldset>
</form>
<div class="form-actions">
<div style="float: right">
<button id="btnFiltro" class="btn btn-primary" onclick="submitFormFiltro();">
<i class="icon-filter icon-white"></i>Filtrar
</button>
<button class="btn btn-primary" onclick="limparFiltro();">
Limpar
</button>
</div>
</div>
</div>
</div>
</div>
And the snippet of code I’m trying for my Javascript file:
$("#formFiltros").on("kepress", function (e) {
var k = event.keyCode || e.which;
if (k == 13) {
// filter and show result
$(this).toggle($(this).text().indexOf(value) > -1)
$("#formFiltros").submit()
}
});
I already tried it this way, made the filter, but when I clicked the Enter button, did not give me the expected result, I will leave the code snippet I did and filtered, but it did not work with the keyboard click event.
$("#GrupoEmpresaAutoComplete").on("keyup", function () {
searchText = $(this).val();
searchText = searchText.toLowerCase();
searchText = searchText.replace(/\s+/g, '');
$('.CelebreTableRow > td').each(function () {
var currentTdText = $(this).text(),
showcurrentTd = ((currentTdText.toLowerCase()).replace(/\s+/g, '')).indexOf(searchText) !== -1;
$(this).toggle(showcurrentTd);
});
});
Thank you for your attention, I hope I’ve made it clear or at least explained the problem I’m trying to solve!
Whoa, you said you didn’t get the expected result, what did you get? Another question in your question is whether you want to call the form action or just make a local filter.
– André Lins
The filter runs only for the name and when I press the Enter key does not show the data of the client that was typed in the input. I want to filter location, as if it was a Submit with the Enter key, I typed the name in the name input, I click on the Enter keyboard and it returns the data from the name typed in the input.
– J. Moura