access the columns array from API ?

access the columns array from API ?

BosephJohnsonBosephJohnson Posts: 11Questions: 4Answers: 0

I'm talking about the columns array that I define in the options.data.columns or the one I get in the ajax callback in data.columns. Where do I get it from the table object?

Answers

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    See the Accessing the API docs to learn how to get the Datatables API object. In some callbacks like initComplete the API can be accessed using this.api().

    If this doesn't help then please provide more details of what you are trying to do.

    Kevin

  • BosephJohnsonBosephJohnson Posts: 11Questions: 4Answers: 0

    I'm just trying to access an array that should look something like this:

    This screenshot is from a log of the data argument in options.ajax when it's used as a function. I'd like to retrieve this array from the api.

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    The settings() API will allow you to interrogate the Datatable settings. Is this what you are looking for?

    If this sin't what you are looking for the please describe what you are trying to do with the information so we can offer better suggestions.

    Kevin

  • BosephJohnsonBosephJohnson Posts: 11Questions: 4Answers: 0

    all I need is just an array containing column metadata, like in the screenshot

    there's no way that this API doesn't expose this array somehow, but I can't find it

    settings() is good start, but so far, anything I run on settings(), like settings().columns() just gives me another instance to the API, not the array of columns that I need

    Also, like I told you, this array IS exposed in data.columns in options.ajax(data, callback, settings), so it must be available somewhere in the API

    It's actually weird that I'm having to explain myself so much right now. I appreciate that you'd like to clarify what exactly I need, but haven't I already made clear what I need? Just an array of column metadata, that's it, nothing crazy.

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    It's actually weird that I'm having to explain myself so much right now. I appreciate that you'd like to clarify what exactly I need, but haven't I already made clear what I need?

    Sorry that I don't understand what you are asking for nor how/when you are trying to use the information. Its a vague question. You haven't posted you Datatables config so we understand what you have.

    This screenshot is from a log of the data argument in options.ajax when it's used as a function. I'd like to retrieve this array from the api.

    This lead me to believe the screenshot was from the Ajax response and you wanted something from the Ajax response.

    But now I suspect you have serverrSide processing enabled and are looking at the request parameters. Datatables derives these parameters from the settings() API. Maybe this example will help.
    https://live.datatables.net/pivanowe/1/edit

    You can use preXhr to access the data sent to the server. If you are trying to do something with it for each request.

    Again if this doesn't help then please provide information of how you want to use this information and when you want to use it. There are lots of options and everyone has different configs and requirements. The more specific you are the better the answers will be :smile:

    Kevin

  • kthorngrenkthorngren Posts: 21,341Questions: 26Answers: 4,954

    Also there are column() APIs that can be used to get much of the information. This is preferable over accessing the API directly. See the settings() docs for. details of why direct access is not recommended.

    See the API page and click the DataTables- Columns button to filter the API list down to just the columns APIs.

    Kevin

  • allanallan Posts: 63,522Questions: 1Answers: 10,473 Site admin

    The object you showed is not one that will be part of the DataTables settings object. Unless you know DataTables inside out, I would strongly suggest you don't use the settings object at all. Indeed, even then it should be avoided.

    What is confusing me certainly, and possibly Kevin as well, is you mention options.data.columns. That isn't a DataTables property. Perhaps you are Ajax loading the configuration for the DataTable and that is what you want to access?

    This is why the forum rules state that a test case must be provided, so we can see what is going on and hopefully get to an answer quickly.

    Remember, you have all the information about what you are looking for and your coding environment. We just have that one image that you posted above. At the moment, we don't have enough information to be able to help.

    My guess is that a DataTables configuration is being loaded from somewhere (the object you provided a glimpse of above certainly looks like a DataTables column configuration array for initialisation), and you are trying to access that. But I don't know.

    Allan

Sign In or Register to comment.