How to get aoColumns settings object?

How to get aoColumns settings object?

ndick2007ndick2007 Posts: 5Questions: 2Answers: 0

I used to get the aoColumns object using the code below. It seems that I am unable to do this after upgrading. How should I go about doing this in the current version? I can see the object in the .setting() function but have no idea how to get to it.

var oTable = $("#" + tableId).dataTable();
var aoColumns = oTable.dataTableSettings[0].aoColumns;
var columns = [];
for(var i=0; i < aoColumns.length; i++) {
if(aoColumns[i].mDataType == undefined) {
columns.push({sTitle: aoColumns[i].sTitle, mData: aoColumns[i].mData});
} else {
if(aoColumns[i].mDataType != "hide4Export") {
columns.push({sTitle: aoColumns[i].sTitle, mData: aoColumns[i].mData, mDataType: aoColumns[i].mDataType});
}
}
}

Answers

  • allanallan Posts: 62,945Questions: 1Answers: 10,356 Site admin

    The settings object is considered to be internal - as you are seeing it can, will and does change between versions. It is also not documented.

    You could use settings() to get the settings object (keep in mind it returns an array).

    Allan

  • ndick2007ndick2007 Posts: 5Questions: 2Answers: 0

    Correct. I actually just looked at my only other question and I was warned. For someone who is admittedly bad with reading and using javascript objects and arrays and is a learner by example. What would be the code to get to aoColumns inside settings()?

  • allanallan Posts: 62,945Questions: 1Answers: 10,356 Site admin

    table.settings()[0].aoColumns should do it.

    Allan

This discussion has been closed.