2016-06-08 36 views
1

我還是一個數據表和ajax的新手。我想問的是如何使編輯鏈接上的每一行數據都顯示在數據表中? 我在頁面pc_list_barcode.php上寫了一個查詢。 daftar_barcode.php頁面顯示查詢結果。如何創建鏈接編輯數據表和ajax。

<?php 
 
include "class/connect_sql.class.php"; 
 
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) 
 
{ 
 

 

 
    
 
    $query = mssql_query("select TOP 30 barcode_wo_nmr, barcode_wo_line,wo_wks_desc, 
 
\t \t \t barcode_wo_proses, barcode_npk, barcode_start, barcode_pending, barcode_end,barcode_qty,barcode_ng,barcode_reason_pending 
 
\t \t \t from WO_ENG_BARCODE, WO_ENG_DET, WO_ENG_DET_WKS with(nolock) where 
 
\t \t \t barcode_wo_nmr= WO_DET_NOMOR and barcode_line = wo_det_line and 
 
\t \t \t barcode_wo_nmr = wo_wks_nmr and WO_DET_NOMOR = wo_wks_nmr and barcode_wo_line = wo_wks_line and WO_DET_NAMA_BARANG = wo_wks_barang and right(barcode_wo_nmr,2) = '15' 
 
\t \t \t order by barcode_wo_nmr asc"); 
 
    $jsonResult = '{"data" : [ '; 
 
    $i=0; 
 
    while ($data=mssql_fetch_assoc($query)) 
 
\t { 
 
     if($i != 0) 
 
\t { 
 
      $jsonResult .=','; 
 
     } 
 
     $jsonResult .=json_encode($data); 
 
     $i++; 
 
\t $data['barcode_wo_nmr']; 
 
\t $data['wo_wks_desc']; 
 
\t $data['barcode_wo_line']; 
 
\t $data['barcode_wo_proses']; 
 
\t $data['barcode_npk']; 
 
\t $data['barcode_start']; 
 
\t $data['barcode_pending']; 
 
\t $data['barcode_end']; 
 
\t $data['barcode_qty']; 
 
\t $data['barcode_ng']; 
 
\t $data['barcode_reason_pending']; 
 
\t  
 
    } 
 
    $jsonResult .= ']}'; 
 
    echo $jsonResult; 
 
} 
 
else { 
 
    echo '<script>window.location="404.html"</script>'; 
 
} 
 
?>
<!doctype html> 
 
<html> 
 
    <head> 
 
     <title>Work Order</title> 
 
     <link rel="stylesheet" href="asset/media/css/bootstrap.min.css"/> 
 
     <link rel="stylesheet" href="asset/media/css/dataTables.bootstrap.css"/> 
 
    </head> 
 
    <body> 
 
     <div class="container"> 
 
      <div class="row"> 
 
       <div class="col-lg-12"> 
 
        <div class="panel panel-default"> 
 
         <div class="panel-heading"> 
 
          
 
          <div class="btn-group pull-right"> 
 
           <a href="#">Add</a> 
 
          </div> 
 
         </div> 
 
         <!-- /.panel-heading --> 
 
         <div class="panel-body"> 
 
          <div class="table-responsive"> 
 
           <table class="table table-striped table-bordered table-hover" id="provinsi"> 
 
            <thead> 
 
             <tr> 
 
              <th>No WO</th> 
 
              <th>Deskripsi</th> 
 
\t \t \t \t \t \t \t \t \t \t \t <th>Line</th> 
 
              <th>Proses</th> 
 
\t \t \t \t \t \t \t \t \t \t \t <th>NPK</th> 
 
              <th>Mulai</th> 
 
\t \t \t \t \t \t \t \t \t \t \t <th>Pending</th> 
 
              <th>Selesai</th> 
 
\t \t \t \t \t \t \t \t \t \t \t <th>QTY</th> 
 
              <th>Not Good</th> 
 
\t \t \t \t \t \t \t \t \t \t \t <th>Reason</th> 
 
\t \t \t \t \t \t \t \t \t \t \t <th>Action</th> 
 
              
 
\t \t \t \t \t \t \t \t \t \t \t 
 
             </tr> 
 
            </thead> 
 
           </table> 
 
          </div> 
 
         </div> 
 
         <!-- /.panel-body --> 
 
        </div> 
 
        <!-- /.panel --> 
 
       </div> 
 
       <!-- /.col-lg-12 --> 
 
      </div> 
 
     </div> 
 
     
 
     <script src="asset/script/jquery-2.1.4.min.js"></script> 
 
     <script src="asset/bootstrap-3.3.6-dist/bootstrap.min.js"></script> 
 
     <script src="asset/media/js/jquery.dataTables.js"></script> 
 
     <script src="asset/media/js/dataTables.bootstrap.js"></script> 
 
     <script> 
 
      $(document).ready(function() { 
 
       var t = $('#provinsi').DataTable({ 
 
        "ajax": "pc_list_barcode.php", 
 
        "order": [[ 1, 'asc' ]], 
 
        "columns": [ 
 
         { 
 
          "data": "barcode_wo_nmr", 
 
          "width": "120px", 
 
          "sClass": "text-center" 
 
         }, 
 
         { "data": "wo_wks_desc" }, 
 
\t \t \t \t \t \t { "data": "barcode_wo_line" }, 
 
\t \t \t \t \t \t { "data": "barcode_wo_proses" }, 
 
\t \t \t \t \t \t { "data": "barcode_npk" }, 
 
\t \t \t \t \t \t { "data": "barcode_start" }, 
 
\t \t \t \t \t \t { "data": "barcode_pending" }, 
 
\t \t \t \t \t \t { "data": "barcode_end" }, 
 
\t \t \t \t \t \t { "data": "barcode_qty" }, 
 
\t \t \t \t \t \t { "data": "barcode_ng" }, 
 
\t \t \t \t \t \t { "data": "barcode_reason_pending" }, 
 
\t \t \t \t \t \t // {"data": return '<a href="edit_barcode.php?id=' + row.id + '">EDIT</a>' }, 
 
        ] 
 
       }); 
 
      }); 
 
     </script> 
 
    </body> 
 
</html>

回答

1

你的數據從11個方面,你的表頭有12個領域,你的DataTable的初始化有9個或10個字段...如果你想扭捏的HTML返回到行你會需要渲染功能,從你的描述,應該大概是這樣的:

{ 
    "data": "unique_id", 
    "render": function(data){ 
     return '<a href="edit_barcode.php?id=' + data + '">EDIT</a>' 
    } 
} 

我不能看到那裏的row.id你引用的是在您被設置PHP的JSON創作,所以我不知道在哪裏unique_id應該來自。基本上你需要改變你的用例,但如果你用這個代替你的註釋行,它應該會有所幫助。

希望有所幫助。

+0

謝謝:)它的工作:D .. terimakasih banyak .. –

+0

快樂好,很高興成爲幫助。 – annoyingmouse

+0

對不起:),有人想問。如何在每一行添加序列號? –