0

I need to fill DIV container, i.e. create a table using 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.

The below shown php file is located in folder main/tables, while all scripts are located in 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>
3
  • Have you tried including the datatables CSS? Commented May 21, 2012 at 18:35
  • Yes,I tried. Nothing has changed. Commented May 21, 2012 at 19:23
  • What's the difference between jsjquery.dataTables.js and jquery.dataTables.min.js? Are they both a copy of the datatables plugin? Commented May 21, 2012 at 19:45

2 Answers 2

2

You are missing the css file. Add it and your problem should be solved.

Sign up to request clarification or add additional context in comments.

Comments

0

I think you need to add in main jquery file. Like;

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

*jQuery UI is not the same as the jQuery library file. 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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.