Tai Nguyen
Tai Nguyen

Reputation: 956

JQuery dataTable table.column not defined

I am using currently DataTable, but I have this following error:

table.columns is not defined

$selector.html(data);
var table = $selector.find('table').DataTable({
  "bLengthChange": false,
  "order": [[ 0, "desc" ]],
  initComplete: function() {
    table.columns().every( function () {
       var that = this;
       $('input', this.footer()).on('keyup change', function () {
         if ( that.search() !== this.value ) {
           that
             .search( this.value )
             .draw();
         }
       });
    });
  }
});

What is wrong with my code?

Upvotes: 1

Views: 1134

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58880

Variable table is not yet defined when initComplete callback is called.

Change

initComplete: function() {
    table.columns().every( function () {

to

initComplete: function(settings){
   var api = new $.fn.dataTable.Api(settings);
   api.columns().every( function () {

Upvotes: 3

Related Questions