Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error dataTable is not a function

I'm trying to use datatables plugin, but i get an error when calling the function dataTable(). My code looks like this:

@Scripts.Render("~/Scripts/DataTables-1.9.4/media/js/jquery.js")
@Scripts.Render("~/Scripts/DataTables-1.9.4/media/js/jquery.dataTables.js")

<script type="text/javascript">
    $(function () {
        $('#tableID').dataTable();
    });
</script>

<table class="table table-striped table-hover table-bordered" id="tableID">
    <thead>
        <tr>
            <th>Column 1</th>
            <th>Column 2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>Row 1</td>
            <td>Row 1</td>
        </tr>
        <tr>
            <td>Row 2</td>
            <td>Row 2</td>
        </tr>
    </tbody>
</table>

When I run it, I can see an error in Firebug:

TypeError: $(...).dataTable is not a function
$('#tableID').dataTable();

In Firebug I can see the jquery.dataTables.js file included, but the function dataTable() doesn't work.

like image 465
user3234688 Avatar asked Mar 16 '14 08:03

user3234688


1 Answers

for me works move definition out of box

Instead of

<script type="text/javascript">
    $(function () {
        $('#tableID').dataTable();
    });
</script>

I use

<script type="text/javascript">
    $('#tableID').dataTable();
</script>

and it Works perfectly.

like image 167
Petr Kobelka Avatar answered Sep 29 '22 15:09

Petr Kobelka