14

I am using the jquery DataTables plugin on my application and I am really happy so far with the functionality although I would like to pass the data slightly differently to the aaData attribute.

currently it only seems to accept the javascript array as

 [
    ['value','value','value'],
    ...,
    ...,
]

I would like to be able to use an object rather than arrays because it will be cleaner and help me extend some filtering I am doing easier. how can I pass it a javascript variable that looks like this ( not loading via AJAX ).

[
   {'id':1,'status':0,'name': 'hello world'},
   ...,
   ...,
]

Example trying to use sAjaxSource with local variable http://live.datatables.net/utecax/edit#

Example trying to use array of objects with aaData http://live.datatables.net/iyavud/5/edit

8
  • 1
    something like this? datatables.net/release-datatables/examples/ajax/objects.html Commented Jan 4, 2013 at 16:38
  • yea the problem I have with that is I am not loading via an external source. data is just a javascript variable and then "sAjaxSource" complains Commented Jan 4, 2013 at 16:40
  • have you tried using aaData instead of sAjaxSource?.. then define your columns as in the example? Commented Jan 4, 2013 at 16:47
  • yea I can only get aaData to take an array of arrays which is somewhat clumsy I think when it comes to referencing it especially when I am using a plugin for filtering and setting the expected column which differs between tables. will udpate with live examples in a sec. Commented Jan 4, 2013 at 16:51
  • works fine here using aaData. You just had the wrong properties set in your columns live.datatables.net/iyavud/6/edit Commented Jan 4, 2013 at 16:57

1 Answer 1

30

You can pass in the array of objects via aaData property, then use aoColumns property to define which column should recieve which data

  $('#example').dataTable({
        "bProcessing": true,
        "aaData": data,// <-- your array of objects
        "aoColumns": [
            { "mData": "render_engine" }, // <-- which values to use inside object
            { "mData": "browser" },
            { "mData": "platform" },
            { "mData": "enging_version" },
            { "mData": "css_grade" }
        ]
  });
Sign up to request clarification or add additional context in comments.

2 Comments

Solution worked fine, but the link provided is not related to the problem.
In new version of datatables.net 1.10.12, the aaData becomes data and aoColumns becomes columns; Updated solution can be found in JSFiddle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.