0
I’m having some difficulties in Jquery, using Datatables, where by clicking select a value in drop-list and clicking the "search" button, it makes an ajax and updates the Datatables with the data selected in the drop list.
However, I would like to apply an effect to an HTML element, which simply displays a "load" icon while the table is not finished loading.
In my code, apparently it only displays the "effect icon" at the end of loading, interestingly it does not show the beginning.
Follows 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>
Segue 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 would like to know where I am missing in the code, because the effect does not start, just ends.
Ps: Datatables is loading normally without difficulties.
see if this link helps: https://www.gyrocode.com/articles/jquery-datatables-how-to-show-loading-indicator-during-table-reload/
– aa_sp