Help with download_link
Help with download_link

Hello! I'm using the function to create a link from the data source.
This is the code from the DataTables columns.render page:
"columnDefs": [ {
"targets": 0,
"data": "download_link",
"render": function ( data, type, full, meta ) {
return '<a href="'+data+'">Download</a>';
}
} ]
And this is my code:
"columnDefs": [ {
"targets": 3,
"data": "download_link",
"render": function ( data, type, full, meta ) {
return '<a href="http://www.mcwd.org/docs/resolutions/'+data+'" target="_blank">Download</a>';
}
} ]
It isn't working. the "+data+" becomes "undefined" in a browser.
The URL to the page is http://www.mcwd.org/about_resolutions_alt2.html
This discussion has been closed.
Replies
Hi
After looking at the data in your table which looks like this for a row.
It seems you are
columns.data
as an object for data when your data is in array format. You don't need to specifycolumns.data
at all because its automatically set to the column index which in this case is 3.Thanks
Tom
Thanks. Yes, if I remove the code I showed above, then "Resolution No. 2016-37.pdf" appears in the cell for column 3. But how do I make "Resolution No. 2016-37.pdf" a hyperlink if not using columns.render? Sorry if I'm being dense. I just don't get it.
So
download_link
doesn't exist anywhere in your data as you are using a 2D array.When you are setting data to
download_link
it will be undefined as your table data is in a 2D array format not an object. This means the data for the column will automatically be applied but you cannot set the data by calling the object's name, only the index of the data inside the array.Instead of setting data to be an undefined object, set it to the column index of the data you want.
Alternatively if you want to call an object for your data, change the data from being a 2D array to be an array of objects, you can then set the data you want to include in the link like you already are above.
e.g.
Would become
See
data
for more information.Thanks
Tom
Just to clarify you can have the same code as before but just remove the
data:
property.e.g
Thank you, Tom!
My code above was in error. I actually used the column name, "res_img," and I also tried "row[3]." But ... just removing the "data" property did the trick!
Again, thank you, thank you, thank you.