2017-12-18 200 views
0

我想知道如何添加一行點擊時,它將用戶重定向到一個頁面。但我無法找到任何在互聯網上如何做到這一點。這是我的代碼。帶鏈接的可點擊數據錶行。 CodeIgniter

控制器

public function ajax_list() 
    { 
     $list = $this->Infoserbilis_model->get_datatables(); 
     $data = array(); 
     $no = $_POST['start']; 
     foreach ($list as $tblcontent) { 
      $no++; 
      $row = array(); 
      $row[] = $no; 
      $row[] = $tblcontent->record_id; 
      $row[] = $tblcontent->title; 
      $row[] = $tblcontent->description; 
      $row[] = $tblcontent->type_id; 
      $row[] = $tblcontent->date_input; 
      $row[] = $tblcontent->encoded_by; 
      $row[] = $tblcontent->updated_by; 
      $row[] = $tblcontent->keywords; 
      $row[] = $tblcontent->broadclass_id; 
      $row[] = $tblcontent->agency_id; 
      $row[] = $tblcontent->contact_id; 
      $row[] = $tblcontent->approved; 
      $row[] = $tblcontent->approved_by; 
      $data[] = $row; 
     } 
    } 

,這是我的看法

<table> 
       <tr> 
        <th>id</th> 
        <th>Record ID</th> 
        <th>Title</th> 
        <th>Description</th> 
        <th>Type</th> 
        <th>Encoded By</th> 
        <th>Updated By</th> 
        <th>Keywords</th> 
        <th>Broad Class</th> 
        <th>Agency</th> 
        <th>Contact</th> 
        <th>Approved?</th> 
        <th>Approved By</th> 
       </tr> 
     </table> 
<script type="text/javascript"> 
var table; 
$(document).ready(function() { 
    table = $('#table').DataTable({ 
     "responsive": true, 
     "processing": true, 
     "serverSide": true, 
     "order": [], 
     "ajax": { 
      "url": "<?php echo site_url('Infoserbilis/ajax_list')?>", 
      "type": "POST" 
     }, 
     "columnDefs": [ 
     { 
      "targets": [ 0 ], 
      "orderable": false, 
     }, 
     ], 
    }); 
}); 
</script> 

請幫我補充另一列在那裏的所有的內容都只是按鈕/鏈接。提前致謝。

+0

你的意思是,你想將用戶重定向到一個頁面上,如果他們點擊表中的行? – Geshode

回答

0

做這樣的事情

datatbl = $('.datatable').dataTable({ 
     stateSave: true, 
     processing: true, 
     serverSide: true, 
     searchDelay: 500, 
     ajax: { 
      url: site_url('url'), 
      type: "POST" 
     }, 
     order: [[ 0, "desc" ]], 
     columns: [ 
      { data: "data.data_id", className : 'data_id'}, 
      { data : "data.data_id", className: "action", orderable: false,searchable: false} 
     ], 
     fnRowCallback : process_row, 
    }); 
    function process_row(nRow, aData, iDisplayIndex) { 
     var oSettings = datatbl.fnSettings(); 
     data_id = $('td.data_id', nRow).html(); 
     $('td.data_id', nRow).html(oSettings._iDisplayStart+iDisplayIndex +1); 


     $('td.action', nRow).html(
      "<a href='"+site_url('url/view/'+data_id)+"' class='btn btn-xs btn-rm'><i class='fa fa-eye'></i> View</a> " 
      + 
      "<a href='"+site_url('url/edit/'+data_id)+"' class='btn btn-xs btn-rm'><i class='fa fa-pencil fa-fw'></i>Edit</a> " 
     ); 
     return nRow; 
    }