lundi 16 septembre 2019

is there is any way to the to delete hidden checkbox in Jquery datatables,How i delete the checked checkbox of previous pages which are not visible?

<script>  
  
   
    
    
    //Delete conformation message
    /***************************/
    

    
    //SelectAll checkBox
    /****************************/
    $(document).ready(function(){ 
        
        var table= $('#testtable').DataTable({
            autoWidth: true,
            "processing": true,
            "serverSide": false,
            "deferRender": true,
             
            order: [[ 1, "asc" ]]
        });
    $('#checkall').click(function(){
         var checked = this.checked;

        table.column(0).nodes().to$().each(function(index) {

      if (checked) {

            $(this).find('.delete_checkbox').prop('checked', 'checked');

          } 
          else {

              $(this).find('.delete_checkbox').removeProp('checked');

              }

         });

       table.draw();
    });
    /********************************/
        
    
    //Select indivisual checkBox
    /*******************************/
    $('.delete_checkbox').click(function(){
         

        if($(this).is(':checked'))
        {
            $(this).closest('tr').addClass('removeRow');
        }
        else
        {
            $(this).closest('tr').removeClass('removeRow');
        }
    });
    /*******************************/
    


    //Deletion of Data
       /***********************************/
        $('#delete_all').click(function(){    
             
        var checkbox = $('.delete_checkbox:checked');
        
        
        if(checkbox.length > 0)
        {  
            var result=confirm("Are you sure");
            if(result==true)
            {
                var checkbox_valu = [];
            $(checkbox).each(function(){
                checkbox_valu.push($(this).val());
            });

            $.ajax({
                url:"delete.php",
                method:"POST",
                data:{checkbox_id:checkbox_valu},
                success:function()
                {
                    $('.removeRow').fadeOut(1500);
                    location.reload(true)

                }
            });
            }
            else {
                return false;
            }

            
        }
        
        else
        {
            alert("Select atleast one records");
        }
    });
      /******************************************/
 
    
    




    

});

  
</script>
<style>
.removeRow
{
    background-color: #FF0000;
    color:#FFFFFF;
}
</style>
<html>  
    <head>  
        <title>Delete Multiple Records using PHP Ajax with Animated Effect</title>
 <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
 <script src="https://cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
 <link rel="stylesheet" href="https://cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">

   

        
    </head>  
    <body >  
        <div class="container">  
            <br />
   <div class="table-responsive">  
    <h3 align="center">Delete Multiple Records using PHP Ajax with Animated Effect</h3><br />
    <div class="table-responsive">
                                <input type="checkbox" id="checkall" autocomplete="off"/>
                                <button type="button"  id="delete_all" class="btn btn-danger btn-xs">Delete</button> 
                    <table id ="testtable" class="table table-bordered">
                        <thead>
                        <tr>
                            <th class='no-sort' width="10%">
                              
                                
                                                          
                                
                            </th>
                            <th width="20%">Name</th>
                            <th width="38%">Address</th>
                            <th width="7%">Gender</th>
                            <th width="25%">Designation</th>
                            <th width="5%">Age</th>
                        </tr>
                        </thead>
                        <?php
                        foreach($result as $row)
                        {
                            echo '
                            <tr>
                                <td>
                                    <input type="checkbox" name="delete_checkbox" autocomplete="off" class="delete_checkbox" value="'.$row["id"].'" />
                                </td>
                                <td>'.$row["name"].'</td>
                                <td>'.$row["address"].'</td>
                                <td>'.$row["gender"].'</td>
                                <td>'.$row["designation"].'</td>
                                <td>'.$row["age"].'</td>
                            </tr>
                            ';
                        }
                        ?>
                    </table>
                </div>
   </div>  
  </div>
    </body>  
</html> strong text

Please suggest some easy and explainable solution according to my code. when I select multiple check boxes on different pages, the check boxes do remain selected properly - the problem is that when I delete the check boxes , it only sends the values of the currently showing page.

For example, if I have 5 pages of data, and I select 2 check boxes from each page (totaling 10), only the values of 2 of the check boxes get passed on.`




Aucun commentaire:

Enregistrer un commentaire