我的表中有大量的列(42),如果我选择复选框,则仅该列数据显示在打印页面上

时间:2019-07-06 10:37:15

标签: javascript php jquery html codeigniter

我的表中有大量的列(42),并且无法在打印中打印所有列,因此我在表标题<th><input type="checkbox"/>LR No</th>中提供了复选框,我只想在打印页面中显示选中的复选框数据

以下是controller

中我的表代码的一些示例记录
 <?php 

     $modelResult = $this->reportModel->bookingRegisterReportByLrno($data);

    ?>
      <table id="bilty_table" class="table table-bordered table-striped table-sm" style="display:block; overflow: auto; " width="100%">
                <thead>
                 <tr>
                  <th><input type="checkbox"/>LR No</th>
                  <th><input type="checkbox"/>Consignor Name</th>
                  <th><input type="checkbox"/>Consignor GSTIN</th>
                  <th><input type="checkbox"/>Consignee Name</th>
               </tr>
            </thead>
                <tbody>

                    <?php foreach($modelResult as $bilty){?>
                <tr>
                  <td><?php echo $bilty->lr_no;?></td>
                  <td><?php echo $bilty->consignor;?></td>
                  <td><?php echo $bilty->consignor_gst_no;?></td>
                  <td><?php echo $bilty->consignee;?></td>
                </tr>
                <?php }?>
                </tbody>
      </table>

这是我的打印页面

<section class="content" style="overflow: auto;">
      <div class="row">
          <table id="booking_register_table" class="table table-striped" width="100%"> </table>
      </div> 
    </div>
  </section>


  <script>

        $(document).ready(function($) {

          var from_date_bk  = "<?php echo isset($_POST['from_date_bk'])? $_POST['from_date_bk'] :''; ?>";
          var to_date_bk    = "<?php echo isset($_POST['to_date_bk'])? $_POST['to_date_bk'] :''; ?>";
          var lr_from       = "<?php echo isset($_POST['lr_from'])? $_POST['lr_from'] : '';  ?>";
          var lr_to         = "<?php echo isset($_POST['lr_to'])? $_POST['lr_to'] : '';  ?>";
          var lr_pay_mode   = "<?php echo isset($_POST['lr_pay_mode'])? $_POST['lr_pay_mode'] : '';  ?>";
          var orderby       = "<?php echo isset($_POST['orderby'])? $_POST['orderby'] : '';  ?>";

          $.ajax({
               url :"<?php echo base_url(); ?>booking/report/booking_register/BookingRegisterController/bookingRegisterReport",
               type: 'POST', 
               async:false,              
               data: {
                from_date_bk:from_date_bk,
                to_date_bk:to_date_bk,
                lr_from:lr_from,
                lr_to:lr_to,
                lr_pay_mode:lr_pay_mode,
                orderby:orderby
               },
               dataType: "html",
               success: function(data){
                  console.log(data);
                  $('#booking_register_table').html(data);
               },
               error:function(data){
                console.log('error occured during fetch');

               }
           });


    $('#booking_register_table').DataTable( {
        dom: 'Bfrtip',
        "pageLength": 100,

        buttons: [
            {
                extend: 'print',className: "btn btn-primary",
                customize: function ( win ) {
                    $(win.document.body)
                        .css( 'font-size', '10pt' )
                        .prepend(
                            '<h2 align="center"><font color="#5CAAFF">Barque Trans And Logistics P.V.T.L.T.D</font></h2>'+
                      '<h3 align="center" ><font color="#5CAAFF">Safeguarding Valuables</font></h3>'+
                      '<hr style="height: 1px;">'+
                      '<h5 align="center"><strong>REPORT FOR BOOKING REGISTER</strong></h5>');

                    $(win.document.body).find( 'table' )
                        .addClass( 'compact' )
                        .css( 'font-size', 'inherit' );
                },
                 title: '',
                exportOptions: {
                    columns: ':visible'
                }
            },
            {
                extend: 'colvisGroup',
                text: 'Show all',
                show: ':hidden'
            },
            {
                extend: 'colvis',
                text: 'Select Columns',

            },
            {
                extend: 'colvisGroup',
                text: 'Office Use',
                show: [ 0,1,19,2,4,8,10,23,14,33,34,35,36,39 ],
                hide: [ 3,5,6,7,9,11,12,13,15,16,17,18,19,20,21,22,24,25,26,27,28,29,30,31,32 ]
            },

        ],
        columnDefs: [ {
            targets: -1,
            visible: false
        } ]
    } );
} );

</script>

如何仅打印记录的选定列

0 个答案:

没有答案