[英]how to make first column of data table as hyperlink
to draw a data table i used below code 绘制我在下面的代码中使用的数据表
function getDataTable(data1) {
var cols = [];
var exampleRecord = data1[0];
var keys = Object.keys(exampleRecord);
keys.forEach(function(k) {
cols.push({
title: k,
data: k
//optionally do some type detection here for render function
});
});
var table = $('#queryBuilderTable').DataTable({
columns: cols
});
//add data and draw
table.rows.add(data1).draw();}
in my first column i got caseId i just want this column as a hyper link so that user can click on that link please help in my code i use json and my JSON KEY is working as column name here. 在我的第一列中,我获得了caseId,我只想将此列作为超级链接,以便用户可以单击该链接,请在我的代码中提供帮助,我使用json,并且我的JSON KEY在此处用作列名。
Try it in the following way 尝试以下方式
$('#queryBuilderTable').dataTable( {
"columnDefs": [ {
"targets": 0,
"data": "The_Link_Defines",
"render": function ( data, type, full, meta ) {
var returnString='';
/*here you can check the condition for making link */
if(your condition with data obj)
returnString ='<a href="'+data+'"> Hyper_Link </a>';
else
returnString ='<span>Text </span>';
return returnString ;
}
} ]
} );
and refer the following Article, Article Link 并参考以下文章, 文章链接
i solved this by using below code 我通过使用以下代码解决了这个问题
var table = $('#queryBuilderTable').DataTable({
"columnDefs": [ {
"targets": 0,
"data": "",
"render": function ( data1, type, full, meta ) {
return '<a onclick="cancerConferenceDataTable('+data1+')" style="cursor: pointer;">'+data1+'</a>';
}
} ],
columns: cols
});
//add data and draw
table.rows.add(data1).draw();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.