William Howley
William Howley

Reputation: 493

Add a Link to a DataTable Column

Hi I am trying to add a link within a datatable column. I am bringing in the information via an array of objects. Here is my implementation. How can I add a new column with a link? I want the link text to be something generic such as "Link" or maybe put in an icon such as

<a href="#"><i class="fa fa-desktop"></i></a>
var createDataTable = function(responseObj){
    adminInfoTable = $('#adminInfoTable').DataTable({
        data: responseObj,
             "columns":[
                    {data:"Date"},
                    {data:"FullName"},
                    {data:"CrossPartyName"},
                    {data:"streetAddress"},
                    {data:"City"},
                    {data:"State"},
                    {data:"Zip5"}
            ]
    });
}

Upvotes: 0

Views: 2576

Answers (1)

William Howley
William Howley

Reputation: 493

I think I figured it out `"columns":[ {data:"Date"}, {data:"FullName"}, {data:"CrossPartyName"}, {data:"streetAddress"}, {data:"City"}, {data:"State"}, {data:"Zip5"}, {data:"PlatBookPageUrl"} ],

            // sets custom render function for the 7th row PlatBookPageUrl
            "columnDefs": [ {
                "targets": 7,
                "data": "PlatBookPageUrl",
                "render": function ( data, type, full, meta ) {
                  return '<a target="_blank" href="'+data+'"><i class="fa fa-desktop"></i></a>';
                }
              } ],`

Upvotes: 3

Related Questions