Cha*_*seC 4 merge datatables multiple-columns
我有这些数据库列,但我希望它们在一列中.我该怎么办?我觉得有了mRender吗?
/* Address */
{"sTitle": "Address",
"bVisible": true,
"bSearchable": true},
/* City */
{"sTitle": "City",
"bVisible": true,
"bSearchable": true},
/* State */
{"sTitle": "State",
"bVisible": true,
"bSearchable": true},
/* Zip */
{"sTitle": "Zip",
"bVisible": true,
"bSearchable": true},
Run Code Online (Sandbox Code Playgroud)
Jay*_*zzi 12
假设datatables返回的列是address,city,state,zip 1-4
如果您返回的数据是常规数组
{ "mData": 0 , //or address field
"mRender" : function ( data, type, full ) {
//data = mData
//full is the full array address= [0] city = [1] state=[2] zip=[3]
return data+', '+full[1]+', '+full[2]+', '+full[3];}
},
Run Code Online (Sandbox Code Playgroud)
如果您的数据是关联数组
{ "mData": 'address' ,
"mRender" : function ( data, type, full ) {
return data+', '+full['city']+', '+full['state']+', '+full['zip'];}
},
Run Code Online (Sandbox Code Playgroud)
或者你可以独立于mData调用mRender(虽然这种情况似乎不需要)
{ "mData": null ,
"mRender" : function ( data, type, full ) {
return full['address']+', '+full['city']+', '+full['state']+', '+full['zip'];}
},
Run Code Online (Sandbox Code Playgroud)
编辑:对于数据表1.10,只需更改名称,删除"m"
{ "data": null ,
"render" : function ( data, type, full ) {
return full['address']+', '+full['city']+', '+full['state']+', '+full['zip'];}
},
Run Code Online (Sandbox Code Playgroud)
*注意我没有考虑是否应该将这些数据存储在一列中,只是说明它是如何完成的