Hyper link in Datatable column

Hyper link in Datatable column

amar.0925@gmail.comamar.0925@gmail.com Posts: 2Questions: 1Answers: 0

I want to display hyper link in datatable column, here is my code.

url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('ZipCodes')/items?"+
"$select=Title,City,State,Link&$filter=(State eq '"+state+"')&$top=5000",
type: "GET",
dataType: "json",
headers: {
Accept: "application/json;odata=verbose"
}

    });
    call.done(function (data,textStatus, jqXHR){
        $('#example').dataTable({
            "bDestroy": true,
            "bProcessing": true,
            "aaData": data.d.results,
            "aoColumns": [
                { "mData": "Title" },
                { "mData": "City" },
                { "mData": "State" },
                { "mData": "<<Hyper link>>" }
            ]
          });
    });

Answers

  • NineForty5NineForty5 Posts: 9Questions: 0Answers: 2

    You can use columns.render to create the link with the option of passing the data as a parameter.

    });
    call.done(function (data,textStatus, jqXHR){
        $('#example').dataTable({
            "bDestroy": true,
            "bProcessing": true,
            "aaData": data.d.results,
            "aoColumns": [
                { "mData": "Title" },
                { "mData": "City" },
                { "mData": "State" },
                { "mData": "Id",
                      "render": function (Id) {
                         return '<a href="http://YourLinkHere/' + Id + '">LinkText</a>';
                         }
                     },
              ]
          });
    });
    
  • amar.0925@gmail.comamar.0925@gmail.com Posts: 2Questions: 1Answers: 0

    it is not working , here is my complete Script .




    <link rel="stylesheet" type="text/css"
    href="http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables.css">

    State: <input type="text" id="State" >
    <input type="button" value="Get Zip Codes" onclick="LoadZipCodes($('#State').val());" >

    Zip CodeCityStateID
    function LoadZipCodes(state) { var call = $.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('ZipCodes')/items?"+ "$select=Title,City,State,Id&$filter=(State eq '"+state+"')&$top=5000", type: "GET", dataType: "json", headers: { Accept: "application/json;odata=verbose" } }); call.done(function (data,textStatus, jqXHR){ $('#example').dataTable({ "bDestroy": true, "bProcessing": true, "aaData": data.d.results, "aoColumns": [ { "mData": "Title" }, { "mData": "City" }, { "mData": "State" }, { "mData": "Id","render": function (Id) { return 'LinkText'; } }, ] }); }); call.fail(function (jqXHR,textStatus,errorThrown){ alert("Error retrieving Tasks: " + jqXHR.responseText); }); }
This discussion has been closed.