2017-02-04 13 views
0

PHPコードに送信した後に行IDを取得したいのですが、datatables jqueryプラグインを使用していますが、IDをdatablesに表示しますが、データ型は入力ではなくtdを生成しています。それはPHPで読むのは簡単だろうが、PHPでdatableの行IDをどのように読むことができるだろう...私は$ _POSTを試したが、私はtdsに何の名前も持たないので、私は傾ける。他のものはcodeigniterを使っています。一度私のIDの行を読むことができます私はid = idのために私のアイテムを更新するために使用することができます。php/codeigniterのdatatables jqueryからIDローを読み取るにはどうすればよいですか?

テーブル

var table = $('#example').DataTable({ 
     "lengthChange": false, 
     responsive: true, 
     dom: 'Blfrtip', 
     buttons: [{ 
      extend: 'excelHtml5', 
      exportOptions:{ 
       columns: [1,2,3,4,5,6] 
      } 
     },{ 
      extend: 'csvHtml5', 
      exportOptions:{ 
       columns: [1,2,3,4,5,6] 
      } 
     },{ 
      extend: 'pdf', 
      exportOptions: { 
       columns: [1,2,3,4,5,6] 
      } 
     }], 
     ajax: { 
      url: URL_GET_DATATABLE, 
      type: 'POST', 
     }, 
     columnDefs:[{ 
      targets: -1, 
      data: null, 
      defaultContent: "<a href='#'><span class='glyphicon glyphicon-pencil'></span></a>" 

     },{ 
      targets: 6, 
      render: function (data) { 
       return (data == 1) ? "<span class='label label-success'>active</span>":"<span class='label label-danger'>inactive</span>"; 
      } 
     }], 
     fnRowCallback: function (data,nRow) { 
      if (nRow[6] == 0) { 
       $(data).css({'background-color':'#f2dede'}); 
      }else if(nRow[6] == 1){ 
       $(data).css({'background-color':'#dff0d8'}); 
      }else{ 

      } 
     } 
    }); 

モデル

public function datatable(){ 
     $this->db->select('id,descripcion,precio_compra,precio_venta,precio_mayoreo,existencia_minima,existencia,storelte_articulos.status'); 
     $this->db->from('storelte_articulos'); 
     $query = $this->db->get(); 
     return $query->result_array(); 
    } 

コントローラ

public function datatable(){ 
     $array = $this->products->datatable(); 
     $this->json($array); 
     $data = array(); 
     foreach ($array as $rows){ 
      array_push($data, array(
       $rows['id'], 
       $rows['descripcion'], 
       $rows['precio_compra'], 
       $rows['precio_venta'], 
       $rows['precio_mayoreo'],  
       $rows['existencia'], 
       $rows['status'] 
      )); 
     } 
     $this->json(array('data' => $data)); 
    } 

更新コントローラ

public function updateProduct($data){ 
     $this->db->update('storelte_articulos',$data); 
     $this->db->where('id'); 
    } 

答えて

0

あなたのIDは入力に入力する必要がありますが、非表示に設定する必要があります。このようにして、データはエンドユーザーには表示されませんが、ポストデータを通じて使用できます。

デベロッパーツール/検査で見ることができるように、それを表示するためにエンコードし、それをデータベースクエリで使用するようにデコードすることをお勧めします。

関連する問題