Datatables - Server-side processing - DB column merging

南楼画角 提交于 2019-12-11 02:17:34

问题


I'm currently using DataTables 1.10.5 server-side processing feature: http://www.datatables.net/examples/data_sources/server_side.html

Haven't done any major modifications yet, just inserted the column names, etc.

$columns = array(
array( 'db' => 'clinicaId', 'dt' => 0 ),
array( 'db' => 'rotaId',  'dt' => 1 ),
array(
    'db'        => 'delegadoId',
    'dt'        => 2,
    'formatter' => function( $d, $row ) {
        $delegado = new Delegado($d);
        return $delegado->display('name');
    }
));

So, in my sql table, I have 2 columns called cp4 (format: 0000), and cp3 (format: 000) that are part of a postal code.

I want to merge those columns into one, when displaying on a datatable (format: 0000-000). This could be solved quickly, by rewriting my SQL tables. But that would defeat the purpose of having them separated, so I can get the specific location it refers to without having to explode the results.

I haven't found anything specific for my struggle. Already wasted about 2 hours on this, any enlightenment will be much appreciated.


回答1:


Try concatenating them:

array( 'db' => '`field1`.`field2`', 'dt' => 'concatenated_fields' ),


来源:https://stackoverflow.com/questions/29147633/datatables-server-side-processing-db-column-merging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!