jQuery datatable如何在第一列添加edit delete链接

时间:2017-05-29 06:24:04

标签: jquery ajax datatables

我想在第一列添加编辑/删除链接。我尝试在$('#table_id').dataTable().fnAddData块中添加代码并不起作用。请帮忙。

<!DOCTYPE html>
<html>
<head>


<link rel="stylesheet" type="text/css"    href="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.css"/>
<script type="text/javascript"   src="jquery-1.12.4.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.15/datatables.min.js"></script>
</head>
<body>
<table width="100%" class="display" id="table_id" cellspacing="0">
  <thead>
          <tr>
          <th>user_id</th>
          <th>role_agent</th>
          <th>role_staff</th>
          <th>status</th>
          <th>create_date</th>
          <th>email</th>
          </tr>
    </thead>
    </tfoot>
           <tr>
           <th>user_id</th>
           <th>role_agent</th>
           <th>role_staff</th>
           <th>status</th>
           <th>create_date</th>
           <th>email</th>
           </tr>
    </tfoot>
  </table>   
  </body>
<script> 
$('#table_id').DataTable();
            $(document).ready(function() {

                $.ajax({
                        type: "POST",
                        url: "getData3a.php",
                        data: {data : ""},
                        cache: false,
                        success: function(result){
                              data = JSON.parse(result);    
                              $.each(data, function(index, data) {     
                              //!!!--Here is the main catch------>fnAddData
                             $('#table_id').dataTable().fnAddData( [ 
                                                                      data.id,
                                                                      data.role_agent,
                                                                      data.role_staff,
                                                                      data.create_date,
                                                                      data.status,
                                                                      data.email ]
                                                                    );

                            });

                        }

                });

            });

</script>





</html>
<!--
$data = array(); 
$row_data = array( 'id' => 1, 'date' => "2014-01-01", 'username' =>    "mou", 'Q1' => "muhahaha" ); 
 array_push($data, $row_data);   

 $row_data = array( 'id' => 9, 'date' => "2013-02-02", 'username' => "sadi", 'Q1' => "hii" ); 
  array_push($data, $row_data);   

  echo json_encode($data);

-->

0 个答案:

没有答案