使列数据作为超链接

使列数据作为超链接

本文介绍了使列数据作为超链接(dataTable JQUERY)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将列作为带有数据表的超链接,但没有成功.

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" },
                ]
  } );

  } );

}

我需要Web链接来显示链接,并在该列中成为超链接,以便用户可以单击并重定向到另一个页面.我调查了渲染,但是链接上的信息较少,我无法成功它.

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.

推荐答案

使用 columns.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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 03:57