数据表 - 将列合并在一起 [英] 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},
推荐答案
前提是datatables get返回的列是address, city, state, zip 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屋!