Can I use Datatables with a Javascript Array of Objects?

Can I use Datatables with a Javascript Array of Objects?

TwitchyTwitchy Posts: 1Questions: 1Answers: 0

Just trying to figure things out and figured you guys might be able to give me a hand.

I am working off of the Javascript Sourced Data page in the examples section, and I am seeing that the arrays are such like:

var Array =[array[]]

The data im using is strickly an Array of Objects such as:

var Array = [object{}]

Unfortunately it seems that the array of objects doesnt work the same way as array of array does. Is anyone able to give me a hand and help me figure out how to make this one work?

Note, I am using Sharepoint Services to get this information, not AJAX or any other sort of information gathering service, thus I do believe the array of objects is all I can get.

Thank you!

Answers

  • DAustinDAustin Posts: 16Questions: 0Answers: 1

    You could map the values to a new array?

    Something like:

    var array= objArray.map(a => a.value);
    

    Then just use that array instead. Won't work on IE8 or older (ES6 required)

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @Twitchy ,

    Yep, that's all good, see this example here. With objects, you need to define the columns, but otherwise all the rest is the same.

    Hope that helps,

    Cheers,

    Colin

This discussion has been closed.