I have some difficulties in JQuery, using DataTables, where when clicking select a value in drop-list and clicking the "search" button, it does an ajax and updates the Datatables with the data selected in the drop list. p>
However, I'd like to apply an effect to an HTML element, which simply displays a "loading" icon while the table does not load.
In my code, it apparently only displays the "effect icon" at the end of loading, curiously it does not display the beginning.
Follow html code:
<button id="search" class="btn btn-primary mr-auto cursor-pointer"><i class="fa fa-search"></i></button>
<div class="fa-2x" id="spinner-loading">
<i class="fa fa-spinner fa-spin"></i>
</div>
Follow js:
$(document).ready(function() {
dataTable();
});
$("#search").on('click', function(event){
$(this).attr('disabled', true);
$('#spinner-loading').fadeIn(300);
event.preventDefault();
var vUsuario = $('#usuarios').val();
dataTable(usuario = vUsuario);
$('#search').attr('disabled', false);
$('#spinner-loading').fadeOut(300);
});
function dataTable(usuario = '') {
$('#tabelaCarteiras').DataTable({
"destroy" : true,
dom: 'Bfrtip',
buttons: [
'excel', 'pdf'
],
fixedHeader: true,
// request
ajax: {
url: '<?=base_url('carteiras/todasCarteiras/')?>' + usuario,
dataSrc: 'data'
},
columns: [
{ data: 'cod_cliente' },
{ data: 'razao_social' },
{ data: 'cod_vendedor' },
{ data: 'telefone1' },
{ data: 'telefone2' }
]
});
};
I'd like to know where I'm going wrong in the code, because the effect does not start, it just ends.
Ps: Datatables are loading normally without any difficulties.