问题描述
我正在尝试将列作为带有数据表的超链接,但没有成功.
I am trying to make a column as hyperlink with datatable but no success.
函数 successCallback(responseObj){
function successCallback(responseObj){
$(document).ready(function() {
$('#example').dataTable( {
"data":responseObj ,
"bDestroy": true,
"deferRender": true ,
"columns": [
{ "data": "infomation" },
{ "data": "weblink" },
]
} );
} );
}
我需要网络链接来显示链接并成为该列中的超链接,以便用户可以单击并重定向到另一个页面.我查看了 render 但链接的信息较少,我无法成功
I need the weblink to display the link and be an hyperlink in that column so users can click and be redirected to another page. I looked into render but with less information there on links, i can't succeed to do it.
我还研究了这个示例,但它不是不是很有帮助.
I also looked into this example but it wasn't very helpful.
推荐答案
使用列.render
API 方法为单元格动态生成内容.
Use columns.render
API method to dynamically produce content for a cell.
$('#example').dataTable({
"data": responseObj,
"columns": [
{ "data": "information" },
{
"data": "weblink",
"render": function(data, type, row, meta){
if(type === 'display'){
data = '<a href="' + data + '">' + data + '</a>';
}
return data;
}
}
]
});
有关代码和演示,请参阅此示例.
See this example for code and demonstration.
这篇关于将列数据设为超链接(dataTable JQUERY)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!