Union query datatable

Union query datatable

ZakXjDatZakXjDat Posts: 1Questions: 1Answers: 0
edited June 2019 in Free community support

this is my query

$bonsrs = DB::table('bon_transfs')
        ->join('sites','bon_transfs.idSiteS' ,'=', 'sites.id')
        ->join('users','bon_transfs.user' ,'=', 'users.id')
        ->select(DB::raw('CONCAT("BTS") AS type'),'bon_transfs.id AS idbon','bon_transfs.created_at AS datebon','bon_transfs.user AS supbon','bon_transfs.prixtotal AS prixtbon','users.name AS nom' )
        ->where('bon_transfs.idSiteS',$id)
        ->whereBetween('bon_transfs.created_at', [$date1, $date2]);
      
        $bons = DB::table('bon_sortie_mags')
        ->join('users','bon_sortie_mags.superviseur' ,'=', 'users.id')
        ->select(DB::raw('CONCAT("BS") AS type'),'bon_sortie_mags.id AS idbon','bon_sortie_mags.created_at AS datebon','bon_sortie_mags.superviseur AS supbon','bon_sortie_mags.prixtotal AS prixtbon','users.name AS nom' )
        ->where('bon_sortie_mags.idSite',$id)
        ->whereBetween('bon_sortie_mags.created_at', [$date1, $date2])
        ->union($bonsrs)
        ->orderBy('datebon', 'asc');

how can i specify colum name in the datatable script

columns: [
                        {   // Responsive control column
                          data: null,
                          defaultContent: '',
                          className: 'control',
                          orderable: false,
                          searchable: false
                        },
                        { data: 'idbon' , 
                          "name" : function ( data, type, row ) {
                                if ( data == "BS" ) {
                                    console.log(data);
                                    return 'bon_sortie_mags.id';
                                    
                                }else{
                                    return 'bon_transfs.id';}
                                } },
                       
                        { data: 'nom' ,name:'users.name'   },
                        
                        { data: 'action', className:'td-actions text-right', name: 'action', orderable: false, searchable: false}
                     ]
This discussion has been closed.