Add button for filtering Today, then list out related only.
Add button for filtering Today, then list out related only.
here is my code, but when i clicked button, it can not get properly information.
<script type="text/javascript" language="javascript" >
$(document).ready(function(){
function filterColumn( value ) {
dataTable.column(1).search( value ).draw();
}
var dataTable = $('#order_data').DataTable({
"processing" : true,
"serverSide" : true,
"columns": [ { "width": "10%" }, null, null, null ],
"order" : [],
"ajax" : {
url:"fetch.php",
type:"POST"
},
drawCallback:function(settings)
{
$('#total_order').html(settings.json.total);
}
});
$('button').on('click', function () {
var today = new Date(); // Get current date
var dd = String(today.getDate()).padStart(2, '0'); // Get day with leading zero
var mm = String(today.getMonth() + 1).padStart(2, '0'); // Get month with leading zero
var yyyy = today.getFullYear(); // Get full year
var currentDate = yyyy + '-' + mm + '-' + dd; // Format the date as 'YYYY-MM-DD'
filterColumn(currentDate);
$(this).text('Filter ' + currentDate); // Update button text
})
});
</script>
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
You're using
serverSide, so the filtering will be done by your server's scripts. It would be worth debugging that server-side script, to ensure it's getting the correct filter values, and if so, debugging that script itself.Colin
I just add filterColumn and no idea how to make it work! any hint for this setup?
Does your server-side script, whatever it is, handle column search data (i.e.
columns[i][search][value]as described in the manual here)? If not, you'd need to add that if you want to use server-side processing.Allan