Php 使数据表的每一行都成为指向ID的超链接
我尝试过其他的解决方案,但都没能成功 如何使数据表的每一行成为指向其ENSG ID的超链接? 我试着在Ajax界面之外做这件事Php 使数据表的每一行都成为指向ID的超链接,php,sql,datatables,Php,Sql,Datatables,我尝试过其他的解决方案,但都没能成功 如何使数据表的每一行成为指向其ENSG ID的超链接? 我试着在Ajax界面之外做这件事 <!DOCTYPE html> <html> <title>Datatable Demo1 | CoderExample</title> <head> <link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css"&g
<!DOCTYPE html>
<html>
<title>Datatable Demo1 | CoderExample</title>
<head>
<link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
<script type="text/javascript" language="javascript" src="js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" >
$(document).ready(function() {
var dataTable = $('#gene-grid').DataTable( {
"processing": true,
"serverSide": true,
"ajax":{
url :"gene-grid-data.php", // json datasource
type: "post", // method , by default get
error: function(){ // error handling
$(".gene-grid-error").html("");
$("#gene-grid").append('<tbody class="gene-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
$("#gene-grid_processing").css("display","none");
}
}
} );
} );
</script>
</head>
<body>
<div class="container">
<table id="gene-grid" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
<thead>
<tr>
<th>ENSG ID</th>
<th>Gene</th>
<th>Biotype</th>
</tr>
</thead>
</table>
</div>
</body>
数据表Demo1 | CoderExample
$(文档).ready(函数(){
var dataTable=$(“#基因网格”)。dataTable({
“处理”:对,
“服务器端”:正确,
“ajax”:{
url:“gene grid data.php”,//json数据源
键入:“post”,//方法,默认为get
错误:函数(){//错误处理
$(“.gene grid error”).html(“”);
$(“#基因网格”).append('在服务器中找不到数据');
$(“#基因网格处理”).css(“显示”、“无”);
}
}
} );
} );
ENSG ID
基因
生物型
我会将行的id存储在数据属性中,然后编写一个单击处理程序来执行此操作。。。请记住,datatables创建动态html,因此如果为正在被销毁和重画的内容设置单击事件,则需要将处理程序附加到父元素。我通常使用body元素
//add this option to datatables initialization
//this will add a data attribute containing the id
//to each row in table.
"rowCallback": function( row, data ) {
$(row).data('id',data.ID);
}
//handler to redirect to detail page...
$('body').on('click', 'tr', function(){
window.location = "http://svr/app/controller/action/" + $(this).data('id');
});
看到这个了吗