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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With