jeudi 29 octobre 2015

how to checkall and delete using jquery

i am using checkall box for check all and deleteing the content. manual selecting and deleting works fine but dont have idea for check all all the value after checking in checkall and delete those item. anybody have idea? please reply

   <div class="col-md-10  mail-right-box">
        <div class="mail-options-nav">
            <div class="input-group select-all" >
                                    <span class="input-group-addon disabled">
                                        <input type="checkbox" id="checkAll" <?php if($pagetitle=="Trash") echo "disabled"?>>
                                    </span>
                <div class="input-group-btn">
                    <button type="button" class="btn btn-default dropdown-toggle <?php if($pagetitle=="Trash") echo "disabled"?>" data-toggle="dropdown" tabindex="-1">
                        <span class="caret"></span>
                        <span class="sr-only">Toggle Dropdown</span>
                    </button>
                    <ul class="dropdown-menu" role="menu">
                        <li><a href="#">Delete</a></li>
                    </ul>
                </div>
            </div><!-- /input-group -->
            <div class="btn-group mail-options">
                <a href="#" class="btn btn-danger <?php if($pagetitle=="Trash") echo "disabled"?>" id="deleteButton"><i class="fa fa-trash-o" ></i> Delete</a>
            </div>
            <div class="mails">
            <table class="table table-hover table-condensed">
                <th></th>
                <th> Subject</th>
                <th>Message</th>
                <th>Email Address</th>
                <th>Date and Time</th>
                <?php
                if(count($inMessages)>0)

                    foreach($inMessages as $m):
                        ?>
                    <!-- php if($m->from!=0 && $m->to!=1): ?> -->
                        <tr class="checkbox1" data-check="<?php echo $m->address?>"  data-to="<?php echo $m->address?>" data-id="<?php echo $m->sn?>" <?php if($m->flag==1) echo "class=\"read\""?><?php if($m->flag==0) echo "class=\"unread\""?> >
                            <td ><?php if($pagetitle!="Trash"):?><i class="fa fa-check-square-o fa-square-o disabled" data-id="<?php echo $m->sn?>"></i><?php endif?></td>
                            <td class="subject"><?php echo $m->subject?></td>
                            <td class="body"><?php echo $m->message?></td>

                            <td class="">
                                <?php echo $m->address?>
                                <BR/><?php echo $m->io?>
                            </td>
                            <td class="time"><?php echo $m->mdate?> <?php echo $m->mtime?></td>
                        </tr>
                    <!--  endif;?> -->
                    <?php
                    endforeach
                ?>
            </table>
        </div>

    </div><!-- /Right Side mail bar -->

i am using checkall box for check all and deleteing the content. manual selecting and deleting works fine but dont have idea for check all all the value after checking in checkall and delete those item. anybody have idea? please reply

and the jquery file custom.s is:

$('document').ready(function(){
var selectedMessages=[];    

$('.mail-right-box .mail-options-nav .input-group .input-group-addon input').click(function(){
        //alert('active');

        $('.mail-right-box .mails table tr td i').addClass('fa-square-o');
        $('.mail-right-box .mails table tr td i.fa-square-o').removeClass('active');
        //$(this).prop('checked', $(this).prop("true"));
        //$(this).addClass('test');
   /* if (this.checked) {

    }*/

});$('.mail-right-box .mails table tr td i').click(function(){
    $(this).toggleClass('active');      
}); 

$('.mail-right-box .mails table tr td i.fa-square-o').click(function(){
    $(this).toggleClass('fa-square-o');
    $(this).parent().parent().toggleClass('active');
    var active=$(this).parent().parent().hasClass('active');
    var id = $(this).attr('data-id');
    if(active){         
        var i = selectedMessages.indexOf(id);
        if(i==-1)
            selectedMessages.push(id);      
    }
    else{       
        var i = selectedMessages.indexOf(id);
        selectedMessages.splice(i,1);
    }
});

    $('#deleteButton').click(function(e){
    var list='';
    for(var i=0;i<selectedMessages.length;i++){
        list=list+selectedMessages[i];  
        var $tr = $('tr[data-id="'+selectedMessages[i]+'"]');
        $tr.remove();
    }
    $.ajax({
        url: 'test/delete.php',
        type: 'POST',
         data: {"points" : JSON.stringify(selectedMessages)},
        success: function(result) {
            bootbox.alert(result);                                              
        }
    });
});

mainly check-all code is inside

$('.mail-right-box .mail-options-nav .input-group .input-group-addon input').click(function(){ code.

please help me




Aucun commentaire:

Enregistrer un commentaire