Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function ajax_list() {
- $list = $this->InfoTable_model->get_datatables();
- $data = array();
- $no = $_POST['start'];
- foreach ($list as $resident) {
- $no++;
- $row = array();
- // $row[] = '<td class="details-control"></td>';
- $row[] = ''; // how do i insert class here where this will generate <td> element
- $row[] = $resident->name;
- $row[] = $resident->lname;
- $row[] = $resident->gender;
- $row[] = date('m/d/Y', strtotime($resident->bday));
- $row[] = $resident->age;
- $row[] = $resident->citizenship;
- $row[] = $resident->occupation;
- $row[] = $resident->status;
- $row[] = $resident->purok;
- $row[] = $resident->resAddress;
- $row[] = $resident->perAddress;
- $row[] = $resident->telNum;
- $row[] = $resident->cpNum;
- //add html for action
- $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>
- <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>';
- $data[] = $row;
- }
- $output = array(
- "draw" => $_POST['draw'],
- "recordsTotal" => $this->InfoTable_model->count_all(),
- "recordsFiltered" => $this->InfoTable_model->count_filtered(),
- "data" => $data,
- );
- //output to json format
- echo json_encode($output);
- }
- var tableData = $('#table').dataTable({
- "oLanguage": {
- "sProcessing": '<center><i class="fa fa-asterisk fa-2x fa-spin text-info"></i></center>'
- },
- "processing": true, //Feature control the processing indicator.
- "serverSide": true, //Feature control DataTables' server-side processing mode.
- "order": [
- [1, 'asc']
- ], //Initial no order.
- // Load data for the table's content from an Ajax source
- "ajax": {
- "url": window.location.origin + "/InfoTable/ajax_list",
- "type": "POST"
- },
- //Set column definition initialisation properties.
- "columnDefs": [{
- "targets": [-1, 0], //last column
- "orderable": false //set not orderable
- }],
- "lengthMenu": [
- [5, 10, 15, 20, 25],
- [5, 10, 15, 20, 25]
- ]
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement