1
I am implementing a web application and already have the full CRUD and search implementation. However, I want to use ajax to make the system more efficient and implement the database search using ajax. I started implementing but not running with ajax, when searching the result is overlapping what was already listed previously, as you can see below. What is wrong or missing so that ajax can do this search on my system correctly.
$(document).ready(function() {
$("#searchForm").submit(function(event) {
// Stop form from submitting normally
event.preventDefault();
// Get some values from elements on the page:
var $form = $(this),
term = $form.find("input[name='parametroBusca']").val(),
url = $form.attr("action");
// Send the data using post
var posting = $.post(
url, {
parametroBusca: term
},
myPostWasSuccessful,
'html'
);
});
});
function myPostWasSuccessful(data, textStatus, jqXHR) {
$("#result").html(data);
}
My list of registered users:
<div class="panel panel-default">
<div class="panel-heading">
<button type="submit" class="btn btn-success" onclick="window.location.href='/funcionarios/formFuncionarios';"> Novo funcionário</button>
<form id="searchForm" class="navbar-form navbar-right"><input type="text" class="form-control" name="parametroBusca" value="${parametroBusca}" placeholder="Buscar...">
</form>
</div>
<div class="panel-body">
<input type="hidden" name="funcionario.id" value="${f?.id}" />
<ul class="list-group">
#{list items:funcionarios, as:'f'}
<li class="list-group-item">
<div class="checkbox" id="result">
<label> ${f.nome} </label>
<div class="pull-right action-buttons">
<a href="@{funcionarios.editarFuncionarios(f.id)}" class="edit"><span class="glyphicon glyphicon-pencil"> Editar</span></a>
<a href="@{funcionarios.removerFuncionarios(f.id)}" class="trash" data-toggle="confirmation" data-btn-ok-label="Sim" data-btn-ok-class="btn-success" data-btn-cancel-label="Não" data-btn-cancel-class="btn-danger" data-title="Remover funcionário" data-content="Tem certeza que deseja excluir este registro?"><span class="glyphicon glyphicon-trash" > Remover</span></a>
<a href="@{funcionarios.detalhesFuncionarios(f.id)}" class="flag"><span class="glyphicon glyphicon-eye-open"> Detalhes</span></a>
</div>
</div>
</li>
#{/list}
</ul>
</div>
and my user listing action:
public static void listagemFuncionarios(String parametroBusca) {
List<Funcionario> funcionarios = null;
if (parametroBusca == null) {
funcionarios = Funcionario.find("status != ?", Status.INATIVO).fetch();
} else {
funcionarios = Funcionario.find("lower(nome) like ? or lower(funcao) like ?", "%" + parametroBusca.toLowerCase() + "%", "%" + parametroBusca.toLowerCase() + "%").fetch();
}
render(funcionarios, parametroBusca);
}
All users already appear in your list? And you’re looking for a specific user?
– usuario
all are listing normally, so the search can list by a specific user according to his name or function, only that in the search is with this bug. In the example above I have 3 registered where the third one is called administrator, in the search I’m only catching Diego.
– Carlos Diego
Why not use jQuery Datatable? It already does this for you. I think it will be a better and faster solution. Take a look at it: https://datatables.net/
– usuario
Vlw by tip @EGDEV, I will try to implement now.
– Carlos Diego
Blz. Anything to call.
– usuario
@Edgve Master of jQuery kk sorry to bother you so much, but I’m in need of help again. Give me a hand with this Datatable https://answall.com/questions/220728/tabela-datatable-workingcorrectly
– Carlos Diego