Where is meta.settings.aoColumns since DataTables 3?

Where is meta.settings.aoColumns since DataTables 3?

elstupidelstupid Posts: 32Questions: 6Answers: 1

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

  • kthorngrenkthorngren Posts: 22,498Questions: 26Answers: 5,170
    Answer ✓

    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:

    const myVar = meta.settings.columns[0].title.replace('b', '');

    If this doesn't help then please post more code and description of what you are trying to do.

    Kevin

  • allanallan Posts: 65,884Questions: 1Answers: 10,960 Site admin

    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

  • elstupidelstupid Posts: 32Questions: 6Answers: 1
    edited August 9

    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.

  • kthorngrenkthorngren Posts: 22,498Questions: 26Answers: 5,170

    I wonder if it might be better to use createdRow for this as it will allow using standard Datatables APIs. Within createdRow you can use column().title() to get the header title or column().name() to get the name. For example:
    https://live.datatables.net/xikukoja/1/edit

    Kevin

  • elstupidelstupid Posts: 32Questions: 6Answers: 1

    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].name

    Still I think you would classify this as non-API or internal, because I use the meta.settings?

  • allanallan Posts: 65,884Questions: 1Answers: 10,960 Site admin

    The context object is the internal settings object of DataTables - it is the same as meta.settings - i.e. in your code above:

    meta.settings === meta.settings.api.columns().context[0]
    

    So all you've done is added some extra characters and clock cycles :).

    You could do:

    meta.settings.api().column(meta.col).name()
    

    But perhaps for the moment you are as well sticking with your original - it will be faster.

    Allan

  • elstupidelstupid Posts: 32Questions: 6Answers: 1

    Yeah we hate extra clock cycles B) I will leave it as is then, thanks!

Sign In or Register to comment.