Showing displayed url links from JSON file clickable to download a file
Showing displayed url links from JSON file clickable to download a file
![[Deleted User]](https://secure.gravatar.com/avatar/22e649c501306c9aa077f905dbd6ee8f/?default=https%3A%2F%2Fvanillicon.com%2F22e649c501306c9aa077f905dbd6ee8f_200.png&rating=g&size=120)
Hi There,
I've had a look at this and don't get it. https://datatables.net/reference/option/columns.render
I need to show column 3 display data (url's) as clickable.
$(document).ready(function() {
$('#example').DataTable( {
"columnDefs": [ {
"targets": 3,
"data": "download_link",
"render": function ( data, type, row, meta ) {
return '<a href="'+data+'">Download</a>';
}
} ]
<!--"serverSide": true,-->
<!--"processing": true,-->
"ajax":{
"url":"https://opendata.arcgis.com/datasets/TheFile.geojson",
"dataSrc": "features"
<!--"dataSrc": "tableData"-->
},
"columns": [
{ "data": "properties.BoreholeId"},
{ "data": "properties.ArchiveId" },
{ "data": "properties.Description" },
{ "data": "properties.UNCPath" },
],
dom: 'lfrtBip',
buttons: [
'copy', 'csv'
]
});
Is this possible with the column render api?
Cheers
RockE
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Yep, that's possible, the problem is that you're defining
columnDefs
andcolumns
, so the former will be over-written.Try this instead:
Colin
Awesome thanks Colin
The properties.UNCPath was already a URL so I wanted to display that, I found this reference return '<a href="'+data+'">'+data+'</a>'; which was what I was looking for.
Is it possible to modify this part
{ "data": "properties.UNCPath", "render": function ( data, type, row, meta ) {
return '<a href="'+data+'">Download</a>';
} },
],
So that if the data is null it doesn't display a download link just a blank space?
Use an if statement and if the data is null use
return "";
else return the link.Kevin
Thanks Kevin, is that a datatables specific if statement or standard javascript? I don't know javascript if it is so will need to search for it :-)
Standard Javascript. It would look something like this:
Didn't test it so there maybe syntax errors.
Kevin
Thanks Kevin, I'll give that a whirl or try this https://www.w3schools.com/js/js_if_else.asp