daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jul 22nd, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function getUser(Request $request)
  2. {
  3.  
  4.   $columns = array(
  5.       0 => 'auto_num',
  6.       1 => 'add_time',
  7.       2 => 'id'
  8.     );
  9.  
  10.     $totalData = DataTes::count();
  11.     $limit = $request->input('length');
  12.     $start = $request->input('start');
  13.     $order = $columns[$request->input('order.0.column')];
  14.     $dir = $request->input('order.0.dir');
  15.  
  16.     if(empty($request->input('search.value'))){
  17.         $posts = DataTes::offset($start)
  18.                 ->limit($limit)
  19.                 ->orderBy($order,$dir)
  20.                 ->get();
  21.         $totalFiltered = DataTes::count();
  22.     }else{
  23.         $search = $request->input('search.value');
  24.         $posts = DataTes::where('auto_num', 'like', "%{$search}%")
  25.                         ->orWhere('add_time','like',"%{$search}%")
  26.           ->orWhere('id','like',"%{$search}%")
  27.                         ->offset($start)
  28.                         ->limit($limit)
  29.                         ->orderBy($order, $dir)
  30.                         ->get();
  31.         $totalFiltered = DataTes::where('auto_num', 'like', "%{$search}%")
  32.                         ->orWhere('add_time','like',"%{$search}%")
  33.           ->orWhere('id','like',"%{$search}%")
  34.                         ->count();
  35.     }
  36.  
  37.  
  38.     $data = array();
  39.  
  40.     if($posts){
  41.         foreach($posts as $r){
  42.             $nestedData['auto_num'] = $r->auto_num;
  43.             $nestedData['add_time'] = $r->add_time;
  44.     $nestedData['id'] = $r->id;
  45.             $data[] = $nestedData;
  46.         }
  47.     }
  48.  
  49.     $json_data = array(
  50.         "draw"          => intval($request->input('draw')),
  51.         "recordsTotal"  => intval($totalData),
  52.         "recordsFiltered" => intval($totalFiltered),
  53.         "data"          => $data
  54.     );
  55.  
  56.     echo json_encode($json_data);
  57.  
  58.  
  59. }
  60.    
  61. $('#example1').DataTable( {
  62.     "ordering": true,
  63.     'autoWidth': true,
  64.  
  65.             "processing": true,
  66.             "serverSide": true,
  67.             "ajax": {
  68.                 "url":"<?= route('dataProcessing') ?>",
  69.                 "dataType":"json",
  70.                 "type":"POST",
  71.                 "data":{"_token":"<?= csrf_token() ?>"}
  72.             },
  73.             "columns":[
  74.       {"data": "auto_num"},
  75.       {"data": "add_time"},
  76.       {"data": "id"}
  77.             ]
  78.         } );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top