var tabla; //funcion que se ejecuta al inicio function init(){ listar(); $("#fecha_inicio").change(listar); $("#fecha_fin").change(listar); } //funcion listar function listar(){ var fecha_inicio = $("#fecha_inicio").val(); var fecha_fin = $("#fecha_fin").val(); tabla=$('#tbllistado').dataTable({ "aProcessing": true,//activamos el procedimiento del datatable "aServerSide": true,//paginacion y filrado realizados por el server dom: 'Bfrtip',//definimos los elementos del control de la tabla buttons: [ 'copyHtml5', 'excelHtml5', 'csvHtml5', 'pdf' ], "ajax": { url:'../ajax/consultas.php?op=comprasfecha', data:{fecha_inicio:fecha_inicio, fecha_fin:fecha_fin}, type: "get", dataType : "json", error:function(e){ console.log(e.responseText); } }, "bDestroy":true, "iDisplayLength":10,//paginacion "order":[[0,"desc"]]//ordenar (columna, orden) }).DataTable(); } init();