数据表-合并列 [英] Datatables - Merge columns together
问题描述
我有这些数据库列,但我希望它们在同一列中.我该怎么做?我认为使用mRender吗?
I have these database columns, but I want them to be in one column. How would I do that? With mRender, I think?
/* 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},
推荐答案
假定数据表返回的列是地址,城市,州,邮政编码1-4
provided that the columns returned by the datatables get are address, city , state, zip 1-4
如果您返回的数据是常规数组
if your data returned is a regular array
{ "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];}
},
如果您的数据是关联数组
if your data is an associate array
{ "mData": 'address' ,
"mRender" : function ( data, type, full ) {
return data+', '+full['city']+', '+full['state']+', '+full['zip'];}
},
或者您可以独立于mData调用mRender(尽管在这种情况下似乎不需要)
or you can call mRender independent of mData (though it seems not needed for this situation)
{ "mData": null ,
"mRender" : function ( data, type, full ) {
return full['address']+', '+full['city']+', '+full['state']+', '+full['zip'];}
},
对于数据表1.10,只需稍稍更改名称,然后删除"m"
for datatables 1.10, just change the names a bit, drop the "m"
{ "data": null ,
"render" : function ( data, type, full ) {
return full['address']+', '+full['city']+', '+full['state']+', '+full['zip'];}
},
*请注意,我没有考虑您是否应该将这些数据存储在一个列中,只是显示其完成方式
*note i'm not taking into account whether you should store this data in one column, just showing how its done
这篇关于数据表-合并列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!