且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在数据表中发送JSON对象aaData而不是数组

更新时间:2023-12-01 19:40:04

您可以通过aaData属性传递对象数组,然后使用aoColumns属性来定义哪个列应该收到哪些数据



$ $ $ $ $ $$$$$$$$ - 你的对象数组
aoColumns:[
{mData:render_engine},//< - wh使用内部对象
{mData:browser},
{mData:platform},
{mData:enging_version},
{mData:css_grade}
]
});


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

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