make column data as hyperlink (dataTable JQUERY)

后端 未结 3 368
终归单人心
终归单人心 2020-12-08 07:20

I am trying to make a column as hyperlink with datatable but no success.

function successCallback(responseObj){

  $(document).ready(function() {
             


        
相关标签:
3条回答
  • 2020-12-08 07:44

    If you are looking to add link based on other column data then can use the below approach.

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

    I have just changed the render function. data refers to only current column data, while row object refers to entire row of data. Hence we can use this to get any other data for that row.

    0 讨论(0)
  • 2020-12-08 07:44
        $('#example').dataTable( {
      "columnDefs": [ {
        "targets": 0,
        "data": "download_link",
        "render": function ( data, type, full, meta ) {
          return '<a href="'+data+'">Download</a>';
        }
      } ]
    } );
    

    From the documentation. It is quite clear and straightforward to me, what is it specifically that you do do not understand? What errors do you see?

    For a more complete example, see here

    0 讨论(0)
  • 2020-12-08 07:47

    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.

    0 讨论(0)
提交回复
热议问题