mercredi 28 novembre 2018

Datatable Checkbox selection

Script:

<script type="text/javascript">
    $(document).ready(function(){
    $(".datepicker" ).datepicker({ dateFormat: 'dd/mm/yyyy' });
    $('#employeeId').chosen({no_results_text:'No Employees !'});
    $('#workScheduleId').chosen({no_results_text:'No Employees !'});

    });

    $(document).ready(function() {
        var oTable = $('#order-listing').dataTable( {
            initComplete: function () {
                this.api().columns().every( function () {
                    var column = this;
                    var select = $('<select><option value=""></option></select>')
                        .appendTo( $(column.footer()).empty() )
                        .on( 'change', function () {
                            var val = $.fn.dataTable.util.escapeRegex(
                                $(this).val()
                            );

                            column
                                .search( val ? '^'+val+'$' : '', true, false )
                                .draw();
                        } );

                    column.data().unique().sort().each( function ( d, j ) {
                        select.append( '<option value="'+d+'">'+d+'</option>' )
                    } );
                } );
            },
            columnDefs: [ {
                orderable: false,
                className: 'select-checkbox',
                targets:   0
            } ],
            select: {
                style:    'multi',
                selector: 'td:first-child'
            },
            lengthMenu: [[20,50, 100, -1], [20, 50, 100, "All"]],
            pageLength: 20 
         } );
        var allPages = oTable.fnGetNodes();

        $('body').on('click', '#selectAll', function () {
            if ($(this).hasClass('allChecked')) {
                $('input[type="checkbox"]', allPages).prop('checked', false);
            } else {
                $('input[type="checkbox"]', allPages).prop('checked', true);
            }
            $(this).toggleClass('allChecked');
        });



    } );

</script>

View:

<div class="code" id="code"> 
        <table id="order-listing" class="table">
            <thead>
                <tr class="bg-light">
                    <th><input type="checkbox" name="selectAll" id="selectAll" class="form-control" data-to-table="tasks" value=1></th>
                    <th>Code</th>
                    <th>Name</th>

                </tr>
            </thead>
            <tbody class="reportData">
                <?php
                    if(is_array($datas)){
                    foreach($datas as $data){
                ?>

                <tr>
                    <td class="a-center "><input type="checkbox" name="selectall[]" class="form-control" value="<?php echo $data['Id']; ?>"/></td>
                    <td><?php echo $data['Code'];?></td> 
                    <td><?php echo $data['Name'];?></td>

                </tr>
                <?php
                    }
                    }else{
                ?>
                <?php
                    }   
                ?>
            </tbody>

        </table>
    </div>
</div>
<div class="shift_category form-group">
    <button type="button" class="btn btn-default" data-dismiss="modal" >Close</button>
    <button type="submit" class="btn btn-primary">Submit</button>
</div>

Here is my datatable view & Script.When I select some values using checkbox from morethan one pages,Only the last page values are inserted into database.I want the values from all pages that i have selected.How to solve this issue.Please help me .....................................................................




Aucun commentaire:

Enregistrer un commentaire