문제

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"
        }
    ]
}
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top