Trying to Add IF Statement w/ Render
Trying to Add IF Statement w/ Render
Here is my code
{ data: "Link_PDF", render: function ( data, type, row ) {
if (data == '') {
return '';
}
else {
return '<a href='+ data +'><i class="fa fa-file fa-lg"></i></a>';
}
}
},
I have an edit page: http://www.skywateryachts.com/datatables_editor_test/boats.html and a quick search for "Namo" will show you the boat Namoh (id- 301) and in a far column I have the URL to a PDF file titled Link_PDF within the cell.
I tried the If statement above in the view page at: http://www.skywateryachts.com/dataviews_test/boats.html so that this display page will render a font awesome PDF img with a link to the file. But in the same search "Namo" there is no image/link in the Link_PDF column cell it is just blank.
Answers
That is because there is nothing with "Namo" in the returned string that DataTables can use to search on.
Have a read through the orthogonal data manual page - particularly using computed values. Basically you want to use the
type
parameter that is being passed into the function to know what data to return.Allan
Hi Allan,
I think I may not have been clear.
I have a column called "Link_PDF" and I placed a pdf link in that cell for the Namoh boat. (I just thought to clarify if someone wanted to see it they could search for the boat in the search box and see the link.)
Anyway, with the above code, below is what I want to happen with the if statement:
Hope this clarifies it.
Thanks
Also to add:
The editor page http://www.skywateryachts.com/datatables_editor_test/boats.html has an URL pdf link in the "Link_PDF" column for the boat Namoh. I have the editor page displaying the URL.
The view page http://www.skywateryachts.com/dataviews_test/boats.html I have the html code in the same "Link_PDF" column using Render as <a href='+ data +'><i class="fa fa-file fa-lg"></i></a> and want to view the Awesome Fonts PDF icon as a link using the URL for the Namoh boat where I have added the URL.
Ah I see. Using the browser's inspect tools I can see that the HTML is being inserted into the document:
However - I don't see FontAwesome being loaded anywhere on your page and the
i
element doesn't have any styling information to show an icon. It looks like you just need to load FontAwesome.Btw - the
href
is null because you havedata == ''
, butLink_PDF
isnull
... :-)Allan