doulanli6146 2015-10-05 18:16
浏览 30

Datatable jquery插件无法在php中运行

I am using data-table jquery plugin for displaying table. The site is built using php. I have a guest page ( guests.php ) to display a table. When I run the site sorting and search function disappears and all data appears on same page. I tried changing the file name to ( guests.html ) it worked fine. But I need to run it on php file. The code for displaying data is as follows:

<?php
    $query="SELECT * FROM guests ORDER BY gue_id DESC";
    $result= mysqli_query($con, $query);
    $s = 1;

    if(mysqli_affected_rows($con)!=0)
    {
        while ($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){

            echo "<tr>";
            echo "<td class='a-center'>
            <input type='checkbox' class='tableflat'>
        </td>";
            echo "<td>" .$row['gue_name']. "</td>";
            echo "<td>" .$row['gue_mail']. "</td>";
            echo "<td>" .$row['gue_mob']. "</td>";
            echo "<td>" .$row['ev_name']. "</td>";
            echo "<td>" .$row['gue_ticket_no']. "</td>";
            echo "<td>" .$row['gue_rsvp']. "</td>";
            echo "<td class='last'>
            <a href='#' class='btn btn-info btn-xs'><i class='fa fa-pencil'></i> Edit </a>
            <a href='#' class='btn btn-danger btn-xs'><i class='fa fa-trash-o'></i> Delete </a></td>";

            echo "</tr>";
            $s++;
        }
    }
  ?>

js Script as below

<script src="../assets/js/datatables/js/jquery.dataTables.js"></script>
    <script src="../assets/js/datatables/tools/js/dataTables.tableTools.js"></script>
    <script>
        $(document).ready(function () {
            $('input.tableflat').iCheck({
                checkboxClass: 'icheckbox_flat-green',
                radioClass: 'iradio_flat-green'
            });
        });

        var asInitVals = new Array();
        $(document).ready(function () {
            var oTable = $('#example').dataTable({
                "oLanguage": {
                    "sSearch": "Search all columns:"
                },
                "aoColumnDefs": [
                    {
                        'bSortable': false,
                        'aTargets': [0]
                    } //disables sorting for column one
        ],
                'iDisplayLength': 12,
                "sPaginationType": "full_numbers",
                "dom": 'T<"clear">lfrtip',
                "tableTools": {
                    "sSwfPath": "<?php echo base_url('assets2/js/Datatables/tools/swf/copy_csv_xls_pdf.swf'); ?>"
                }
            });
            $("tfoot input").keyup(function () {
                /* Filter on the column based on the index of this element's parent <th> */
                oTable.fnFilter(this.value, $("tfoot th").index($(this).parent()));
            });
            $("tfoot input").each(function (i) {
                asInitVals[i] = this.value;
            });
            $("tfoot input").focus(function () {
                if (this.className == "search_init") {
                    this.className = "";
                    this.value = "";
                }
            });
            $("tfoot input").blur(function (i) {
                if (this.value == "") {
                    this.className = "search_init";
                    this.value = asInitVals[$("tfoot input").index(this)];
                }
            });
        });
    </script>

Any suggestions what might be the problem.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 simulink单相桥式整流电路
    • ¥35 问问51单片机流水灯的代码该怎么写
    • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
    • ¥15 stata webuse报错
    • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
    • ¥15 如何利用AI去除图片中的竹架子
    • ¥15 python 写个基金爬取的代码,自动卖出功能
    • ¥15 Linux系统启动不起来
    • ¥15 为什么运行仿真数码管不亮(语言-c语言)
    • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导