Display of objects inside of array

Display of objects inside of array

vhuffmanvhuffman Posts: 4Questions: 1Answers: 0

I am a total newbie to DataTables and I've looked at the examples, but I can't figure my issue out.
I have an Array of Object and I can't figure out how to display them.

I don't have this working on the web, just a local copy.

Here is the data:
javascript_variables: Array[2]
0: Object
name: "variable1"
value: "v1_1234"
proto: Object
1: Object
name: "variable2"
value: "v2_123456789"

aoColumns:
{ "mData": "javascript_variables[, ]", "bSortable": false },

Output in Table on webpage:

[object Object], [object Object]

How can I access the Arrays and then the Object attributes - name and value?

I've tried a few varieties of the following, but haven't been able to figure it out:

Changed my aoColumn definition:
{ "mData": getNameAndValue },

function getNameAndValue(data, type, dataToSet) {
return data.name + "=" + data.value;
}

Thanks,
Vaughn

This question has accepted answers - jump to:

Answers

  • vhuffmanvhuffman Posts: 4Questions: 1Answers: 0

    Here is a link to an example that I'm trying to figure out:
    http://live.datatables.net/zefaxija/1/edit

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Answer ✓

    The columns.data option (which is the modern name for the old mData option) can read data from arrays as explained in its documentation. Thus if you want to show a comma separated list of the plug-in names you would use: {"mData": "plugins[, ].name"}.

    http://live.datatables.net/zefaxija/2/edit

    Allan

  • vhuffmanvhuffman Posts: 4Questions: 1Answers: 0

    Thanks Allan!
    I did notice the names changed, but I didn't know which ones are the modern names.
    I'll play around with the example, but what I really want to get is something like the following:
    plugins.1.name+"="+plugins.1.value+", "+plugins.2.name+"="+plugins.2.value

    Thanks again,
    Vaughn

  • allanallan Posts: 63,161Questions: 1Answers: 10,406 Site admin
    Answer ✓

    For that you would use columns.render as a function. Have data: 'plugins', then the first parameter that is passed into the rendering function is the plugin array and you can simply loop over it building the output string you want.

    Allan

  • vhuffmanvhuffman Posts: 4Questions: 1Answers: 0

    Thanks Allan!
    I'm really loving the DataTables plugin!

This discussion has been closed.