Is there any way to access 'aoData' array?

Is there any way to access 'aoData' array?

shamelessshameless Posts: 31Questions: 0Answers: 0
edited March 2011 in General
Is there anyway to access the initial data used to build a table? To clarify, I am able to access table data via:

[code]
/* Get the data array for this row */
var aPos = oTable.fnGetPosition( this);
var aData = oTable.fnGetData(aPos);
[/code]

...but what I want to be able to do is look at the data initially used to build the table, not the rendered data. Has anyone done this?

Replies

  • allanallan Posts: 63,518Questions: 1Answers: 10,473 Site admin
    DataTables stores all information for each individual table in a settings object, which you can retrieve using fnSettings(). From that there is aoData and a whole host of other parameters. They are all documented in the code, but not (yet) on the web-site. Possibly a console.dir( oTable.fnSettings() ); will help, or browsing the code.

    Allan
  • shamelessshameless Posts: 31Questions: 0Answers: 0
    Thanks for the reply, Alan.

    I just used fnSettings() and iterated over the returned object and aoData is the same as the "rendered" data contained in the table. Or I am overlooking a method. Maybe what I am looking for is not provided, but it seems like being able to correlate a table row to the "original" data would be useful.
  • allanallan Posts: 63,518Questions: 1Answers: 10,473 Site admin
    aoData[].nTr is the element in the table, so that will be what is rendered. But aoData[]._aData will container the text strings ( http://datatables.net/usage/columns#bUseRendered might be useful for you) and there are various other properties as well.

    Allan
  • shamelessshameless Posts: 31Questions: 0Answers: 0
    Alan,

    I'm only getting the rendered, values not the original data.

    I use:
    [code]
    var data = oTable.fnSettings().aoData[aPos]._aData;
    console.log($(data));
    [/code]


    This gives me this result in the JQuery console:
    log: jQuery("", "", "", "", "
  • allanallan Posts: 63,518Questions: 1Answers: 10,473 Site admin
    Sorry I'm not quite following - have you set bUseRendered: false for the column that you want to keep the original data in?

    In your code:
    [code]
    var data = oTable.fnSettings().aoData[aPos]._aData;
    console.log($(data));
    [/code]
    _aData is an array of strings - so I don't really understand why you've wrapped it in a jQuery object?

    Allan
  • shamelessshameless Posts: 31Questions: 0Answers: 0
    Whoops, sorry. Obviously I am not being clear as to my objective: Let me back up and go at it again.

    re: "have you set bUseRendered: false for the column that you want to keep the original data in?" I _think_ that the answer is "sometimes yes" and "sometimes no". I am using aoColumns and on some columns (such as the "id" column) I am setting "bVisible": false" like so:

    /* 1 -- id */ { "bVisible": false }.

    Other columns, such as the ones where I am displaying a checkmark if the value in the JSON is equal to "1", are obviously being rendered as an image in the cell.

    What I want to be able to do is read the original value "1" instead of the rendered value "
  • allanallan Posts: 63,518Questions: 1Answers: 10,473 Site admin
    Thanks for the clarification. Are you actually setting bUseRendered ( http://datatables.net/usage/columns#bUseRendered ) at all in aoColumns? It is default true, so if you want _aData to retain the original value, rather than the rendered one you need to specifically set it to false.

    Allan
  • shamelessshameless Posts: 31Questions: 0Answers: 0
    Wow. That was an easy solution once I managed to let go of my frustration and actually read your reply.

    You should be a Zen Master.
This discussion has been closed.