Add button for filtering Today, then list out related only.

Add button for filtering Today, then list out related only.

kitsontamkitsontam Posts: 5Questions: 3Answers: 0
edited November 2023 in Free community support

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.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    it can not get properly information

    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

  • kitsontamkitsontam Posts: 5Questions: 3Answers: 0

    I just add filterColumn and no idea how to make it work! any hint for this setup?

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin

    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

Sign In or Register to comment.