Reload all data send id and json
Reload all data send id and json
Hello,
I try to refresh the table to each click in which a parameter is sent, I honestly do not know how to do that process.
The following code does what I need but I'm not sure it's the right one.
$('.rsel').click(function(e){
$('#wlista').css('display','block');
idexp = $(this).attr('id');
$('#wlista').find('h2').text($($('figcaption span')[idexp]).text());
if(table != null) {
table.destroy();
}
table = $('#datatable').DataTable({
"autoWidth": false,
"order": [[ 0, "desc" ]],
"processing": true,
"ajax": {
"url":"<?php echo base_url() ?>documentos/getDocExpAjax",
"type": "POST",
"data": {
id_expediente: idexp
},
},
"columns": [
{ "data": "id_documento" },
{ "data": "identificador" },
{ "data": "nombre_documento" },
{ "data": "productor" },
{ "data": "estado"},
{ "data": "accion"}
],
"columnDefs": [
{
"targets" : [5],
"visible" : ("<?php echo $this->session->userdata('codigo') ?>" == 'AD') ? true : false,
"searchable" : ("<?php echo $this->session->userdata('codigo') ?>" == 'AD') ? true : false,
}
],
"language":
{
"url": "<?php echo base_url('vendors/datatables.net/i18n/Spanish.json') ?>"
},
});
});
This discussion has been closed.
Answers
Yes, you don't really want to destroy the table on every click and then recreate it. Use
ajax.reload()and makeajax.dataa function. The documentation shows an example of it with a function, and it basically executes that function whenever theajax.reload()method is called.Allan
Thanks for answering.
I would need to reload for each sending of the parameter, what would the code look like?
I have in mind that the sending of parameters is as follows:
You'd uise the
ajax.dataoption as a function as I mentioned above:The
451could be replaced with a variable or something that you read from the document. It will be evaluated every time you callajax.reload().Allan