简体   繁体   English

jQuery DataTable创建问题

[英]jQuery DataTable creating issue

I need to fill DIV container, ie create a table using jQuery DataTable . 我需要填充DIV容器,即使用jQuery DataTable创建一个表。 The problem is that this example does not work for me. 问题是这个例子对我不起作用。 Instead of formatted table I see the unformatted one without any element of jQuery DataTable plugin. 而不是格式化的表我看到没有任何元素的jQuery DataTable插件的未格式化的表。

The below shown php file is located in folder main/tables , while all scripts are located in main/scripts/media . 下面显示的php文件位于main/tables文件夹中,而所有脚本都位于main/scripts/media

So, what is actually wrong in my code? 那么,我的代码实际上有什么问题呢?

<?php
    include_once 'include/DatabaseConnector.php';
    $query2="SELECT * FROM resources;";
    $result2=DatabaseConnector::ExecuteQueryArray($query2);
?>

<script type="text/javascript" src="../scripts/media/js/jquery.dataTables.min.js"></script>
<script src="../scripts/media/js/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript" src="../scripts/media/js/complete.js"></script>
<script type="text/javascript" src="../scripts/media/jsjquery.dataTables.js"></script>
<script type="text/javascript" src="../scripts/media/js/jquery.dataTables.columnFilter.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    $('#example').dataTable();
} );
</script>

<div>
<h1>Employees</h1>

    <table width="100%">
        <tr>
            <td> 
                <div class="scrollbar">
                <table id="example" border="0" cellspacing="2" cellpadding="2" width = "100%">
                    <thead>
                    <tr>
                        <th scope="col">Reg</th>
                        <th scope="col">Title</th>
                        <th scope="col">Availability</th>
                        <th scope="col">Latitude</th>
                        <th scope="col">Longitude</th>
                        <th scope="col">Average Speed (km/h)</th>
                    </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($result2 as $row):?>
                        <tr class="alternate">
                        <td><?php echo $row['resReg']; ?></td>
                        <td><?php echo $row['resTitle']; ?></td>
                        <td><?php echo $row['resAvailability'] ? 'Yes' : 'No';?></td>
                        <td><?php echo $row['resLatitude']; ?></td>
                        <td><?php echo $row['resLongitude']; ?></td>
                        <td><?php echo $row['resAvgSpeed']; ?></td>
                        </tr>
                        <?php endforeach;?>
                    </tbody>
                </table>
                </div>
            </td>
        </tr>
    </table>
</div>

You are missing the css file. 您缺少css文件。 Add it and your problem should be solved. 添加它,你的问题应该解决。

I think you need to add in main jquery file. 我认为你需要添加主jquery文件。 Like; 喜欢;

<script src="js/jquery-1.10.2.min.js"></script>

*jQuery UI is not the same as the jQuery library file. * jQuery UI与jQuery库文件不同。 And check whether these two files are duplicate or not. 并检查这两个文件是否重复。 If so, you need only one. 如果是这样,你只需要一个。

<script type="text/javascript" src="../scripts/media/js/jquery.dataTables.min.js"></script>

<script type="text/javascript" src="../scripts/media/jsjquery.dataTables.js"></script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM