Reputation: 9
In jquery datatable i am getting error table.column is not a function
<script>
$(document).ready(function() {
var table = $('#lsotable').dataTable();
$("#lsotable thead th").each( function ( i ) {
var select = $('<select><option value=""></option></select>')
.appendTo( $(this).empty() )
.on( 'change', function () {
table.column( i )
.search( $(this).val() )
.draw();
} );
table.column( i ).data().unique().sort().each( function ( d, j ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
} );
</script>
I am getiing the table data from while loops, i want it should be only three columns, how i can do .
Upvotes: 0
Views: 3277
Reputation: 134
I was getting the same error "table.column is not a function" but I've just solved.
Old code:
const table = $('#my_table');
// table.DataTable({...});
table.DataTable();
$('#my_table thead tr:eq(0) th').each(function (i) {
if ($(this).html() === $('#my_search_field').val()) {
table.column(i).search($('#my_search_query').val()).draw();
}
});
New code:
const table = $('#my_table').DataTable();
$('#my_table thead tr:eq(0) th').each(function (i) {
if ($(this).html() === $('#my_search_field').val()) {
table.column(i).search($('#my_search_query').val()).draw();
}
});
It looks ridiculous but solved the issue.
Upvotes: 0
Reputation: 443
Those who are struggling with a similar type of problem in datatable version 1.9.* can have a look on here:
Link
Upvotes: 0
Reputation: 61
Just change the dataTable()
to DataTable()
as shown below.
var table = $('#lsotable').DataTable();
Upvotes: 1
Reputation: 657
Looks like you are using older version of datatable library. I tried with Datatable version 1.10.12 and it works fine.
Upvotes: 0