0

When using jquery.DataTables I run into the following problem consistently when trying to redraw the table from an AJAX source, but it also occurs with any of the API methods I attempt to use.

I am using version 1.10.

Example

var table = $('#table').dataTable( {
    initComplete: function(settings, json) {
        ....
    },
    ajax:  'url',
    serverSide: true,
    order: [[2, 'desc']],
    stateSave: true,
    language: {
        "lengthMenu": "Display _MENU_ records per page",
        "zeroRecords": "Nothing Found",
        "infoEmpty": "Nothing Found",
        "infoFiltered": "(filtered from _MAX_ total records)"
    },
    lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]],
    pageLength: 10,
    lengthChange: true,
    ordering: true,
    paging: true,
    processing: false,
    searching: true
});

setInterval(function(){
    table
        .dataTable()
        .order( [[ 2, 'asc' ]] )
        .draw( false );
}, 30000);

Error

Uncaught TypeError: Object [object Object] has no method 'order'

This is a copy of the example posted in the DT site, which the exception of the DT in the example passing additional parameters upon initialization.

I know the error is due to the table object not having the methods from .dataTable(), but other then that I am not sure how to get it working so that it does the draw(false), or any other API method.

The part that gets me is that a,

table.fnDraw();

Works perfectly fine....

Thank you for the help in advance.

2 Answers 2

1

Change this:

setInterval(function(){
    table
        .dataTable()
        .order( [[ 2, 'asc' ]] )
        .draw( false );
    }, 30000);

to:

setInterval(function(){
    table
        .api()
        .order( [[ 2, 'asc' ]] )
        .draw( false );
}, 30000);
Sign up to request clarification or add additional context in comments.

1 Comment

this worked, thank you. I am requesting an update to the docs from Alan to include this.
0

Try SetInterval Inside Init Complete Function, So It Won't Fire Until The Data Table Is Ready.

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.