I have some JSON sample data, which has a URL object. When I add the data into a datatable, I am getting the URL as text, instead of a link.
var items = [
{
"Alert": "Alpha",
"Date": "23/04/2021",
"Information": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In a ultrices nisl, ac interdum libero. Vestibulum ac convallis mauris, auctor hendrerit augue. Vivamus elementum sapien eget dui maximus, quis laoreet magna pulvinar. Sed feugiat hendrerit est, et tincidunt lorem pellentesque nec. Quisque consequat laoreet eros in porta.",
"Name": "Tester",
"Status": "Live",
"URL": "https://www.google.com/",
"Updated": "21/04/2021 09:35"
}
]
Datatable:
$(document).ready(function () {
var items = JSON.parse(request.responseText);
$('#thisTable').dataTable({
"aaData": items,
columns: [
{ title: "Date", "mDataProp": "Date" },
{ title: "Status", "mDataProp": "Status" },
{ title: "Alert", "mDataProp": "Alert" },
{ title: "Updated", "mDataProp": "Updated"},
{ title: "Name", "mDataProp": "Name" },
{ title: "Information", "mDataProp": "Information" },
{ title: "URL", "mDataProp": "URL"}
],
});
});
I have read through the documentation, which references assigning a function to pick up the URL, however when I include the below I am just getting a console error. First time trying to use datatables with a JSON source, which is a little more complex.
"data": "URL",
"render": function ( data, type, row, meta ) {
return '<a href=" + URL +">LINK</a>';
}