【问题标题】:how to make first column of data table as hyperlink如何将数据表的第一列设为超链接
【发布时间】:2016-04-25 05:39:27
【问题描述】:

绘制我在代码下面使用的数据表

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();}

在我的第一列中,我得到了 caseId,我只想将此列作为超链接,以便用户可以单击该链接,请在我的代码中提供帮助,我使用 json 并且我的 JSON KEY 在此处用作列名。

【问题讨论】:

    标签: jquery json datatables


    【解决方案1】:

    按以下方式试试

        $('#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 ;
        }
      } ]
    } );
    

    并参考以下文章, Article Link

    【讨论】:

    • 感谢您的帮助,但是通过使用上面的代码,它使我的整个表格成为 hiperlink
    • Okey 查看答案和给定链接中的更新。如果它有助于投票并标记为答案。谢谢
    【解决方案2】:

    我用下面的代码解决了这个问题

     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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 2015-08-09
      • 2020-08-20
      相关资源
      最近更新 更多