如何在PHP的数据表中选择两个列

时间:2019-02-08 12:58:44

标签: jquery datatables

如何从数据表中选择两列?

 <div id="page-wrapper">
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">Manage Policy</h1>
                        <div class="panel panel-default">
                            <div class="panel-heading">Manage Policy</div>
                            <div class="panel-body">
                                <div class="well">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <button class="btn btn-default pull-right"> <td><a href="<?php echo $this->url('wfm_job_company_policy'); ?>">Create</a></td>  </button>
                                        </div>
                                      </div>
                                </div>
                                <div class="table-responsive">
                    <table class="table table-striped table-bordered table-hover table-scroll" id="dataTables-example">
                                        <thead>
                                            <tr>
                                                <th style="width:12%">
                                                    Policy ID 
                                                </th>
                                                <th style="width:18%">
                                                     Policy Name   
                                                </th>
                                                <th>
                                                     Upload Document
                                                </th>

                                                <th style="width:5%">
                                                    Action  
                                                </th>
                                            </tr>
                                        </thead>

                                    </table>

                                </div>

                            </div>
                        </div>
                    </div>    
                </div>
            </div>
        <script>
 $(document).ready(function () {
        var oTable = $('#dataTables-example').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": {
                'type': 'POST',
                'url': "<?php echo $this->url('wfm_job_company_policy_man'); ?>",
            },
            "columnDefs": [
                {
                    "render": function (data, type, row) {

                       var pdId = row[4];
                        return '<a href="<?php echo $this->url('company_policy_edit', array("action" => "edit", "id" => "'+pdId+'")) ?>">' + data + '</a>';


                    },
                    "targets": [3] // for target column where need to see the links
                }
            ]

        });

        $('#domSearch').keyup(function () {
            oTable.search($(this).val()).draw();
        });

    });
</script>


 <div id="page-wrapper">
                <div class="row">
                    <div class="col-lg-12">
                        <h1 class="page-header">Manage Policy</h1>
                        <div class="panel panel-default">
                            <div class="panel-heading">Manage Policy</div>
                            <div class="panel-body">
                                <div class="well">
                                    <div class="row">
                                        <div class="col-sm-12">
                                            <button class="btn btn-default pull-right"> <td><a href="<?php echo $this->url('wfm_job_company_policy'); ?>">Create</a></td>  </button>
                                        </div>
                                      </div>
                                </div>
                                <div class="table-responsive">
                    <table class="table table-striped table-bordered table-hover table-scroll" id="dataTables-example">
                                        <thead>
                                            <tr>
                                                <th style="width:12%">
                                                    Policy ID 
                                                </th>
                                                <th style="width:18%">
                                                     Policy Name   
                                                </th>
                                                <th>
                                                     Upload Document
                                                </th>

                                                <th style="width:5%">
                                                    Action  
                                                </th>
                                            </tr>
                                        </thead>
                                      <!--  <tbody>
                                        <?php

                                      //  if (!empty($payitem)):
                                     //foreach ($payitem as $data):
                                        ?>
                                      <tr>

                    <td><?php  //echo $data['pdId']; ?></td>
                    <td><?php // echo $data['pdName']; ?></td>
                    <td><?php //echo $data['fileName']; ?></td>          
                       <td><a href="<?php //echo $this->url('company_policy_edit',array(
                         //'id' => $data['pdId'])); ?>">Edit</a></td> 
                     </tr>
                <?php

            //endforeach;
        //endif;
        ?>
</tbody>-->
                                    </table>

                                </div>

                            </div>
                        </div>
                    </div>    
                </div>
            </div>
        <script>
 $(document).ready(function () {
        var oTable = $('#dataTables-example').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": {
                'type': 'POST',
                'url': "<?php echo $this->url('wfm_job_company_policy_man'); ?>",
            },
            "columnDefs": [
                {
                    "render": function (data, type, row) {

                       var pdId = row[4];
                        return '<a href="<?php echo $this->url('company_policy_edit', array("action" => "edit", "id" => "'+pdId+'")) ?>">' + data + '</a>';


                    },
                    "targets": [3] // for target column where need to see the links
                }
            ]

        });

        $('#domSearch').keyup(function () {
            oTable.search($(this).val()).draw();
        });

    });
</script>

这是我的管理页面。在这里有一个策略文件名,我想在datatable中创建一个pdf downloadble。在这里,我一次只能选择第四行,而现在我想选择第三行。在数据表中排成一行,然后创建一个可点击的pdf文件,例如锚标签。上传文档应该像锚标签一样。

1 个答案:

答案 0 :(得分:0)

要将某些行仅导出为PDF,您需要使用datatables的{​​{3}}和选项select: true组合才能选择特定行。

这是官方buttons中的一个例子。