Where is meta.settings.aoColumns since DataTables 3?
Where is meta.settings.aoColumns since DataTables 3?
In one of my column render functions I have been using meta.settings.aoColumns, but since DT3 aoColumns isn't a property of meta.settings anymore. Where to find this now?
I have been using it like this before, now my code breaks:
const myVar = meta.settings.aoColumns[meta.col].mData.replace('b', '');
This question has an accepted answers - jump to answer
Answers
Please see this note about internal property naming. You can inspect the settings properties using
settings()to find the suitable settings path for the property you are looking for. Possibly something like this:If this doesn't help then please post more code and description of what you are trying to do.
Kevin
Are you able to elaborate on the use case a bit? I'm wondering if there is a way to do it without using the private parameters.
Allan
Thanks for enlightening me. It's a little hard to explain in detail, but long story short, I need the name of the data column, providing the source data from the database. I found it now by using
meta.settings.columns[meta.col].name;The column name value is used to set as a data-property on a button in the cell.
I wonder if it might be better to use
createdRowfor this as it will allow using standard Datatables APIs. WithincreatedRowyou can usecolumn().title()to get the header title orcolumn().name()to get the name. For example:https://live.datatables.net/xikukoja/1/edit
Kevin
That might be usable too. However, my number of colums is dynamic and I need it to work on specific columns, that's why I use it in the column render function. In a createdRow function I would need to check all columns, which feels to me like more overhead and a lot of fiddling.
Using a standard API function would be nicer, on the other hand the render function provides this meta object for a reason I guess
. The meta.settings has an api() object, where I can find the information I need by using
meta.settings.api.columns().context[0].columns[meta.col].nameStill I think you would classify this as non-API or internal, because I use the meta.settings?
The
contextobject is the internal settings object of DataTables - it is the same asmeta.settings- i.e. in your code above:So all you've done is added some extra characters and clock cycles
.
You could do:
But perhaps for the moment you are as well sticking with your original - it will be faster.
Allan
Yeah we hate extra clock cycles
I will leave it as is then, thanks!