TypeError ... is not a function
TypeError ... is not a function
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
Hi Hans,
There is not
settings().init()
method. There isinit()
, just don't call thesettings()
method first. In fact, as it notes in thesettings()
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
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
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 asinit()
sincesettings()
returns an API instance. So thesettings()
call is redundant.Allan
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
Seems to work for me: http://live.datatables.net/kipezabi/1/edit . As I say, I would need a test case.
Because, as I noted above,
settings()
returns a DataTables API instance. That has aninit()
method available. So callingsettings().init()
is exactly the same as just callinginit()
.Allan