column().name() is not a function (version 1.10.15)
column().name() is not a function (version 1.10.15)
dbakewel
Posts: 3Questions: 1Answers: 0
I am trying to get a column name from it's index as stated in the API docs: https://datatables.net/reference/api/column().name()
The following code produces the error: uncaught TypeError: dataTable.columns(...).names is not a function
var dataTable = $("#DataTable").DataTable();
var x = dataTable.column(0).name();
If you can't do this then how do you get a column name from it's index?
I know the column has a working name because this works:
var dataTable = $("#DataTable").DataTable();
var x = dataTable.column("resultId:name").data();
These statements also work just fine:
var dataTable = $("#DataTable").DataTable();
var a = dataTable.column(0).data();
var b = dataTable.column(0).nodes();
var c = dataTable.column(0).header();
Using version 1.10.15 of DataTables and current API docs.
This discussion has been closed.
Answers
Is this something that is in the docs but not in the current version (1.10.15)? If so, is there another way to get the name from the index?
Please note that this works in live.datatables.net but it is using the nightly build: http://live.datatables.net/sododohi/1/edit
Can we see your whole $("#DataTable") table declaration?
The
column().name()
docs indicate the API is available starting in DT 2.0:You are right, if you change your test case to use 1.10.15 the result is the error you noted.
Allan can give you the best recommendation of what to do.
Kevin
Doh! I didn't see the "Since: DataTables 2.0.0". Thanks, I'll keep an eye for that from now on.
Bother - sorry. I didn't mean to deploy that documentation. Kevin is right - that isn't a function that is in the shipping release.
Looks like I've messed up my branches a little. I'll get that fixed!
You could try the 2 branch to get that function (it does work), but it is very very early in the development of v2. Its likely many months away from release!
Allan
At times I found it easier to create my columns as a separate object. Then I can put whatever I need in it as an easy access storage point and use it wherever needed.
Has it been fixed yet?
This is an API designated for Datatables 2.0 which has not been released yet.
Kevin