TypeError ... is not a function

TypeError ... is not a function

hawkmasterhawkmaster Posts: 56Questions: 20Answers: 0

Hello

I am trying some example code from
http://jsfiddle.net/6fstLmb6/
and from;
https://datatables.net/reference/api/row%28%29.id%28%29

The problem is that init() and id() throws an error.

...
oExampleTable = $("#exampletable").DataTable({
....

$('#exampletable tbody').on( 'click', 'td', function () {

var columns = oExampleTable.settings().init().columns;
var colIndex = oExampleTable.cell(this).index().column;
alert('you clicked on the column with the name '+columns[colIndex].name);

}

On table click this returns an error:

TypeError: oExampleTable.settings(...).init is not a function

$('#exampletable tbody').on( 'click', 'tr', function () {

var id = oExampleTable.row( this ).id();
alert( 'Clicked row id '+id );

}

TypeError: oExampleTable.row(...).id is not a function

any idea what is going wrong?
thanks a lot
regards
Hans

Replies

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    Hi Hans,

    oExampleTable.settings().init().columns;

    There is not settings().init() method. There is init(), just don't call the settings() method first. In fact, as it notes in the settings() documentation you should never need to call it. It contains private properties that can, will and do change between versions (I should never have exposed if via the API!).

    Allan

  • hawkmasterhawkmaster Posts: 56Questions: 20Answers: 0

    Hi Alan,
    thanks for the info.
    I have seen this in the the jsfiddle demo. Why does the example work correct there?

    And what is about the id() is not a function error?

    Hans

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    I don't see id() being used in the example. Can you show me an example of it not working please.

    Regarding it working - settings().init() will actually return the same as init() since settings() returns an API instance. So the settings() call is redundant.

    Allan

  • hawkmasterhawkmaster Posts: 56Questions: 20Answers: 0

    The id() example I tried is from the offical site:
    https://datatables.net/reference/api/row%28%29.id%28%29
    I copied the code into my table but then there was the error.

    Sorry if I ask again.
    I have copied the example from the jsfiddle
    $("#example").on('click', 'td', function() {
    //get the initialization options
    var columns = table.settings().init().columns;
    //get the index of the clickec cell
    var colIndex = table.cell(this).index().column;
    alert('you clicked on the column with the name '+columns[colIndex].name);
    })

    to my code, but then had the init() function error.
    You wrote "There is not settings().init() method." but why does it work in this jsfiddle?
    Sorry but I do not understand.

    Hans

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    Seems to work for me: http://live.datatables.net/kipezabi/1/edit . As I say, I would need a test case.

    You wrote "There is not settings().init() method." but why does it work in this jsfiddle?

    Because, as I noted above, settings() returns a DataTables API instance. That has an init() method available. So calling settings().init() is exactly the same as just calling init().

    Allan

This discussion has been closed.