是否可以配置DataTables
来处理对象数组而不是aaData
属性的默认数组数组?
这是我的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"
}
]
}
答案 0 :(得分:1)
是的,添加aoColumns
- 定义初始化:
..
"aoColumns": [
{ "mDataProp": "userid" },
{ "mDataProp": "password" },
{ "mDataProp": "vpn_password" },
{ "mDataProp": "status_id" },
{ "mDataProp": "expire_account" },
{ "mDataProp": "created" }
]
..
如上所述摆弄您的数据 - >的 http://jsfiddle.net/6tK7K/ 强>
重要:如果您使用dataTables v 1.9.2或更高版本,请改用属性名称"mData"
。正如the docs says:
请注意,在DataTables之前,1.9.2 mData被称为mDataProp。该 名称更改反映了此属性的灵活性 与mRender的命名一致。如果' mDataProp'然后给出了 它仍将由DataTables使用,因为它会自动映射旧的 如果需要,可以命名为新的。