Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  33] [ 4]  / answers: 1 / hits: 45069  / 12 Years ago, fri, january 4, 2013, 12:00:00

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


More From » jquery

 Answers
13

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 }
]
});

[#81077] Thursday, January 3, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elmer

Total Points: 432
Total Questions: 96
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
;