将列数据作为超链接(dataTable JQUERY)

Und*_*007 25 jquery datatables datatables-1.10

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

function successCallback(responseObj){

  $(document).ready(function() {
         $('#example').dataTable( {
        "data":responseObj ,
        "bDestroy": true,
        "deferRender": true ,
        "columns": [
                    { "data": "infomation" },
                    { "data": "weblink" },
                ]
  } );

  } );
Run Code Online (Sandbox Code Playgroud)

}

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

我也研究了这个例子,但它没有用.

Gyr*_*com 57

使用columns.renderAPI方法动态生成单元格的内容.

$('#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;
         }
      } 
   ]
});
Run Code Online (Sandbox Code Playgroud)

有关代码和演示,请参阅此示例.


Ada*_*cha 9

如果您要基于其他列数据添加链接,则可以使用以下方法。

$('#example').dataTable({
   "data": responseObj,
   "columns": [
      { "data": "information" }, 
      { 
         "data": "weblink",
         "render": function(data, type, row, meta){
            if(type === 'display'){
                data = '<a href="' + row.myid + '">' + data + '</a>';
            }
            return data;
         }
      } 
   ]
});
Run Code Online (Sandbox Code Playgroud)

我刚刚更改了render函数data仅指当前列数据,而row对象指整个数据行。因此,我们可以使用它来获取该行的任何其他数据。


ozz*_*ozz 7

    $('#example').dataTable( {
  "columnDefs": [ {
    "targets": 0,
    "data": "download_link",
    "render": function ( data, type, full, meta ) {
      return '<a href="'+data+'">Download</a>';
    }
  } ]
} );
Run Code Online (Sandbox Code Playgroud)

文档中.这对我来说是非常清楚和直截了当的,你有什么不明白的?你看到什么错误?

有关更完整的示例,请参见此处