merge - 数据表 - 将列合并在一起

标签 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},

最佳答案

假设数据表 get 返回的列是地址、城市、州、邮政编码 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];}
      },

如果您的数据是关联数组

   { "mData": 'address' , 
     "mRender" : function ( data, type, full ) { 
        return data+', '+full['city']+', '+full['state']+', '+full['zip'];}
      },

或者你可以独立于mData调用mRender(尽管这种情况似乎不需要)

   { "mData": null , 
     "mRender" : function ( data, type, full ) { 
        return full['address']+', '+full['city']+', '+full['state']+', '+full['zip'];}
      },

编辑:对于数据表 1.10,只需稍微更改名称,删除“m”

   { "data": null , 
     "render" : function ( data, type, full ) { 
        return full['address']+', '+full['city']+', '+full['state']+', '+full['zip'];}
      },

*注意,我没有考虑您是否应该将此数据存储在一列中,只是显示其完成方式

关于merge - 数据表 - 将列合并在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19777075/

相关文章:

r - 在r中合并两个数据帧时如何保留索引

git - `--squash` 和 `--no-ff --no-commit` 有什么区别?

git - 将 merge 分支放回到 Git 中

css - 响应列中的嵌入视频在 WebKit 中消失

mysql - 将多行合并为一行 MySQL

mysql - 将 MySQL 转储与现有表合并

datatables - 从 search.push 函数中的 DataTables 获取 'data-sort' 正交值

javascript - 如何将数据表 jQuery 与 ajax 结合使用?

javascript - 表填充后仍保留 "No matching records found"

xpath - 具有XPath的Selenium IDE,可基于其他列识别表中的单元格