Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. public function ajax_list() {
  2. $list = $this->InfoTable_model->get_datatables();
  3. $data = array();
  4. $no = $_POST['start'];
  5. foreach ($list as $resident) {
  6. $no++;
  7. $row = array();
  8. // $row[] = '<td class="details-control"></td>';
  9. $row[] = ''; // how do i insert class here where this will generate <td> element
  10. $row[] = $resident->name;
  11. $row[] = $resident->lname;
  12. $row[] = $resident->gender;
  13. $row[] = date('m/d/Y', strtotime($resident->bday));
  14. $row[] = $resident->age;
  15. $row[] = $resident->citizenship;
  16. $row[] = $resident->occupation;
  17. $row[] = $resident->status;
  18. $row[] = $resident->purok;
  19. $row[] = $resident->resAddress;
  20. $row[] = $resident->perAddress;
  21. $row[] = $resident->telNum;
  22. $row[] = $resident->cpNum;
  23.  
  24. //add html for action
  25. $row[] = '<a class="btn btn-sm btn-primary enable-tooltip" data-toggle="tooltip" href="javascript:void(0)" title="Edit Resident" onclick="edit_resident(' . "'" . $resident->resident_id . "'" . ')"><i class="fa fa-pencil"></i></a>
  26. <a class="btn btn-sm btn-danger enable-tooltip" data-toggle="tooltip" href="javascript:void(0)" title="Delete Resident" onclick="delete_resident(' . "'" . $resident->resident_id . "'" . ')"><i class="fa fa-times"></i></a>';
  27.  
  28. $data[] = $row;
  29. }
  30.  
  31. $output = array(
  32. "draw" => $_POST['draw'],
  33. "recordsTotal" => $this->InfoTable_model->count_all(),
  34. "recordsFiltered" => $this->InfoTable_model->count_filtered(),
  35. "data" => $data,
  36. );
  37. //output to json format
  38. echo json_encode($output);
  39. }
  40.  
  41. var tableData = $('#table').dataTable({
  42. "oLanguage": {
  43. "sProcessing": '<center><i class="fa fa-asterisk fa-2x fa-spin text-info"></i></center>'
  44. },
  45. "processing": true, //Feature control the processing indicator.
  46. "serverSide": true, //Feature control DataTables' server-side processing mode.
  47. "order": [
  48. [1, 'asc']
  49. ], //Initial no order.
  50. // Load data for the table's content from an Ajax source
  51. "ajax": {
  52. "url": window.location.origin + "/InfoTable/ajax_list",
  53. "type": "POST"
  54. },
  55. //Set column definition initialisation properties.
  56. "columnDefs": [{
  57. "targets": [-1, 0], //last column
  58. "orderable": false //set not orderable
  59. }],
  60. "lengthMenu": [
  61. [5, 10, 15, 20, 25],
  62. [5, 10, 15, 20, 25]
  63. ]
  64. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement