0

Is it possible to configure DataTables to hanlde array of objects instead of default array of arrays for aaData propery?

Here is my JSON:

{
    "sEcho": 1,
    "iTotalRecords": "57",
    "iTotalDisplayRecords": "57",
    "aaData": [
        {
            "userid": "tM4Ga0zX",
            "password": "ZKwMEiIa",
            "vpn_password": "K3lS2yn9",
            "status_id": 0,
            "expire_account": "0000-01-01 00:00:00",
            "created": "2014-02-11 09:29:02"
        },
        {
            "userid": "tM4Ga0zX",
            "password": "ZKwMEiIa",
            "vpn_password": "K3lS2yn9",
            "status_id": 0,
            "expire_account": "0000-01-01 00:00:00",
            "created": "2014-02-11 09:29:02"
        },
        {
            "userid": "tM4Ga0zX",
            "password": "ZKwMEiIa",
            "vpn_password": "K3lS2yn9",
            "status_id": 0,
            "expire_account": "0000-01-01 00:00:00",
            "created": "2014-02-11 09:29:02"
        }
    ]
}

1 Answer 1

1

Yes, add an aoColumns-definition your initialization :

..
"aoColumns": [
  { "mDataProp": "userid" }, 
  { "mDataProp": "password" },
  { "mDataProp": "vpn_password" },
  { "mDataProp": "status_id" },
  { "mDataProp": "expire_account" },
  { "mDataProp": "created" }
]
..

fiddle with your data as above -> http://jsfiddle.net/6tK7K/

Important : If you use dataTables v 1.9.2 or above, use the property name "mData" instead. As the docs says :

Note that prior to DataTables 1.9.2 mData was called mDataProp. The name change reflects the flexibility of this property and is consistent with the naming of mRender. If 'mDataProp' is given, then it will still be used by DataTables, as it automatically maps the old name to the new if required.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! How does jsfiddle work if there is no DataTables plugin included?
You are welcome! See the fiddle, to the left there is "External Resources", just added datatables.js and the corresponding css from a CDN. Allan Jardine has now his own CDN up running, cdn.datatables.net - but I think it is still in a kind of beta.

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.