【问题标题】:action button on datatable codeigniter数据表codeigniter上的操作按钮
【发布时间】:2020-02-11 21:26:31
【问题描述】:

您好,我在 codeigniter 上成功实现了数据表,但我遇到了一个问题,我需要在最后一个列表上设置一个操作按钮,例如编辑、删除

这是我在 codeigniter 上制作数据表的方法

正在查看

<div class="table-responsive">
        <table id="table" class="table">
            <thead>
                <tr>
                    <th>Loan</th>
                    <th>Loan Type</th>
                    <th>Loan Amount</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            </tbody>
            <tfoot>
                <tr>
                    <th>Loan</th>
                    <th>Loan Type</th>
                    <th>Loan Amount</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                    <th>Action</th>
                </tr>
            </tfoot>
        </table>

<script type="text/javascript">

    var table;

    $(document).ready(function() {

        //datatables
        table = $('#table').DataTable({ 

            "processing": true, //Feature control the processing indicator.
            "serverSide": true, //Feature control DataTables' server-side processing mode.
            "order": [], //Initial no order.

            // Load data for the table's content from an Ajax source
            "ajax": {
                "url": "<?php echo site_url('home/ajax_list')?>",
                "type": "POST"
            },

            //Set column definition initialisation properties.
            "columnDefs": [
            { 
                "targets": [ 0 ], //first column / numbering column
                "orderable": false, //set not orderable
            },
            ],

        });

    });
    </script>

现在这是我的控制器中的脚本,我在其中通过 json 传递数据。

public function ajax_list()
    {
        $list = $this->employee->get_datatables();
        $data = array();
        $no = $_POST['start'];
        foreach ($list as $customers) {
            $no++;
            $row = array();
            $row[] = $no;
            $row[] = $customers->loan;
            $row[] = $customers->loan_type;
            $row[] = $customers->loan_amount;
            $row[] = $customers->firstname;
            $row[] = $customers->lastname;

            $data[] = $row;
        }

        $output = array(
                        "draw" => $_POST['draw'],
                        "recordsTotal" => $this->employee->count_all(),
                        "recordsFiltered" => $this->employee->count_filtered(),
                        "data" => $data,
                );
        //output to json format
        echo json_encode($output);
    }

是否可以在数据表上添加操作按钮?

【问题讨论】:

  • 试试this,对你有帮助
  • span-html-formatted-text-to-database 能帮到我吗先生
  • 您可以使用 textarea 并在其中输入 html 并在保存之前使用 htmlspecialchars(),这将有助于将 html 保存在数据库中,同时从数据库中拉回使用 htmlentities()

标签: php codeigniter datatable


【解决方案1】:

如果有人可能遇到这样的问题,也许这会对你有所帮助。

$row = array();
            $row[] = $no;
            $row[] = $customers->loan;
            $row[] = $customers->loan_type;
            $row[] = $customers->loan_amount;
            $row[] = $customers->firstname;
            $row[] = $customers->lastname;
            $row[] = '<button type="button" name="update" id="'.$customers->id.'" class="btn btn-warning btn-xs update">Update</button>';

我直接从数据数组中添加了按钮

【讨论】:

    猜你喜欢
    • 2017-10-23
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多