column().name() is not a function (version 1.10.15)

column().name() is not a function (version 1.10.15)

dbakeweldbakewel 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.

Answers

  • dbakeweldbakewel Posts: 3Questions: 1Answers: 0

    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

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    Can we see your whole $("#DataTable") table declaration?

  • kthorngrenkthorngren Posts: 21,363Questions: 26Answers: 4,956

    Is this something that is in the docs but not in the current version (1.10.15)?

    The column().name() docs indicate the API is available starting in DT 2.0:

    Since: DataTables 2.0.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

  • dbakeweldbakewel Posts: 3Questions: 1Answers: 0

    Doh! I didn't see the "Since: DataTables 2.0.0". Thanks, I'll keep an eye for that from now on.

  • allanallan Posts: 63,552Questions: 1Answers: 10,477 Site admin

    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

  • bindridbindrid Posts: 730Questions: 0Answers: 119

    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.

    var cols =[ { data: "first_name", title : "First Name" },
                { data: "last_name" , title: "Last Name"},
                { data: "firstNumber", title: "Number" }];
    
    $("#table").DataTable({"columns":cols});
    
  • nwickinwicki Posts: 21Questions: 8Answers: 0

    Has it been fixed yet?

  • kthorngrenkthorngren Posts: 21,363Questions: 26Answers: 4,956

    This is an API designated for Datatables 2.0 which has not been released yet.

    Kevin

This discussion has been closed.