showing results for - "ajax jquery datatable display records with pagination in laravel"
Lara
11 Aug 2019
1<?php
2
3namespace App\Http\Controllers;
4
5use Illuminate\Http\Request;
6use App\Employees;
7
8class EmployeesController extends Controller{
9
10   public function index(){
11      return view('employees.index'); 
12   }
13
14   /*
15   AJAX request
16   */
17   public function getEmployees(Request $request){
18
19     ## Read value
20     $draw = $request->get('draw');
21     $start = $request->get("start");
22     $rowperpage = $request->get("length"); // Rows display per page
23
24     $columnIndex_arr = $request->get('order');
25     $columnName_arr = $request->get('columns');
26     $order_arr = $request->get('order');
27     $search_arr = $request->get('search');
28
29     $columnIndex = $columnIndex_arr[0]['column']; // Column index
30     $columnName = $columnName_arr[$columnIndex]['data']; // Column name
31     $columnSortOrder = $order_arr[0]['dir']; // asc or desc
32     $searchValue = $search_arr['value']; // Search value
33
34     // Total records
35     $totalRecords = Employees::select('count(*) as allcount')->count();
36     $totalRecordswithFilter = Employees::select('count(*) as allcount')->where('name', 'like', '%' .$searchValue . '%')->count();
37
38     // Fetch records
39     $records = Employees::orderBy($columnName,$columnSortOrder)
40       ->where('employees.name', 'like', '%' .$searchValue . '%')
41       ->select('employees.*')
42       ->skip($start)
43       ->take($rowperpage)
44       ->get();
45
46     $data_arr = array();
47     
48     foreach($records as $record){
49        $id = $record->id;
50        $username = $record->username;
51        $name = $record->name;
52        $email = $record->email;
53
54        $data_arr[] = array(
55          "id" => $id,
56          "username" => $username,
57          "name" => $name,
58          "email" => $email
59        );
60     }
61
62     $response = array(
63        "draw" => intval($draw),
64        "iTotalRecords" => $totalRecords,
65        "iTotalDisplayRecords" => $totalRecordswithFilter,
66        "aaData" => $data_arr
67     );
68
69     echo json_encode($response);
70     exit;
71   }
72}
queries leading to this page
laravel pagination and jquery datatable ajaxdatatables ajax pagination laravellaravel datatables paginationdatatable ajax pagination laraveldynamic pagination in javascript with table data by ajax call examplejquery datatable pagination example codelaravel yarja datatable style paginationlaravel jquery datatable server paginationdatatable pagination laraveljquery datatable example with paginationdatatable laravel paginationdatatable dynamic pagination examplehow to get data paginate data get by ajax jquery in laravellaravel datatable paginationdatatables paginatelaravel datatables ajax pagination examplesdatatable ajax data with pagination search in laraveldatatable bootstrap sort laravellaravel datatables model paginationlaravel pagination datatablesdatatable ajax pagination with laraveluse jquery datatable with laravel paginationlaravel datatables ajax paginationajax jquery datatable display records with pagination in laraveljquery datatable ajax pagination example laraveldatatables dynamic pagination in php laraveldata table pagination laraveldatatables pagination with ajax in laravellaravel yarja datatable styling paginationsorting in serverside pagination in laravel jquery datatabledatatable pagination in laraveldatatable ajax laravelpagination in laravel ajax datatablesjquery datatable in laravellaravel datatable pagination with ajaxsorting the total data table records with paginationlaravel datatable with pagination ajaxajax jquery datatable display records with pagination in laravel