Simple Example for Datatable display
Simple Example for Datatable display. If the html button not displaying in the view page use the escapeColumns([‘id’]) function return Datatables::of($result)->escapeColumns([‘id’])->make(true); Javascript File test.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
$(function () { var site_datatable; var site_data = {}; site_datatable = $('#dashboard_employee').DataTable({ "serverSide": true, "destroy": true, "autoWidth": false, "searching": true, "aaSorting": [2,'asc'], "columnDefs": [ { "targets": 0, "searchable": false } ], "ajax": { type: "GET", data: site_data, url: siteUrl + '/get_empdata', } }) }) |
Php Files
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public function get_empdata() { $result = array(); $whereArray = array(); $empDetails = EmpTable::getimpData($whereArray)->get(); foreach ($empDetails as $id) { $row = array(); $row[] = $id->name; $row[] = $id->age; $row[] = $id->designation; $delete_url = '<span><th style="text-align:center"><button type="button" class="btn btn-danger">Delete</button></th></span>'; $row[] = $delete_url; $result[] = $row; } return Datatables::of($result)->escapeColumns(['id'])->make(true); //return Datatables::of($result)->make(true); // if we are not using the escapeColumns() then the button will not display in the view page } |
view File mypage.php
1 2 3 4 5 6 7 8 9 10 11 |
<table id="dashboard_employee" class="table table-responsive table-bordered table-hover table-striped"> <thead> <tr> <th>Name</th> <th>Age</th> <th>Designation</th> <th>Action</th> </tr> </thead> </table> |