Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending JSON Objects in DataTables aaData instead of arrays

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

like image 361
BillPull Avatar asked Jan 04 '13 16:01

BillPull


1 Answers

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" }
        ]
  });
like image 193
wirey00 Avatar answered Oct 26 '22 19:10

wirey00