render link to absolute path
render link to absolute path
i have a page with a datatable which has a column which renders the data as a link to a file in a (documents) folder, like so...
return '<a href="/documents/'+data+'">'+data+'</a>' ;
if i want to link to an external path I tried just omitting the documents path
return '<a href="'+data+'">'+data+'</a>' ;
but this gives me an error, the generated url looks like this, <a href="plugins'+data+'">'+data+'</a>
presumably because the page containing my datatable is a plugin page (in a folder called plugins), one level below the 'parent' page.
is there a way to generate the absolute url ?
Answers
What is the error?
Not sure how
return '<a href="'+data+'">'+data+'</a>' ;
results in the above URL. Can you post a link to your page or a test case replicating the issue?https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
You should be able to generate any URL you want. Its just a matter of getting the return string to look the way you want. Datatables isn't controlling this.
Kevin
the error is in my console
Uncaught SyntaxError: Invalid or unexpected token
the javascript reads as follows (line 6 below)
which is generated by the code below
I will try and create a cut-down test page tomorrow
Line 6 in your first code snippet has the syntax error. You need to add a single quote before the
+row
:return '<a href="plugins"+row
should be:
return '<a href="plugins"'+row
Kevin
the first code snippet is the javascript generated when the page is loaded in the browser
the second code snippet is what generates the javascript, and there is no syntax error in there
Guess I'm not familiar with how the second code snippet is generating the first. Look forward to seeing this in your test page.
Kevin
i have uploaded sample pages to a test area, (username and password to access are 'nfci'
the 'parent page' is found at this url
http://instagram.forthwebsolutions.com/admin/documents/documentsx.php
the child plugin page is found here
http://instagram.forthwebsolutions.com/admin/documents/plugins/document_resultsx.php
the child page works perfectly fine in its own right, but when embedded in the parent page, the url generated by the javascript incorporates the subfolder name at the beginning of the path, (but only if it is left empty)
so
works fine, in both the child page, and when used as a plugin to the parent page
but
will incorporate the subfolder in the parent page, throwing an error, but is ok in the child page
Sorry, I'm still unclear where
return '<a href="'+data+'">'+data+'</a>' ;
is coming from. I don't see it anywhere in your code.However on line 170 of your parent page there is this line:
Which is missing the single quote I mentioned above. If you have something generating the Javascript for this page then you need to look at that code to determine why it is not generated correctly. This is outside the scope of Datatables.
Kevin
if you look at the child page, you will see the following javascript generated (the page renders properly and the link works as it should)...
if you look at the parent page, you will see this
there is no syntax error, but because the folder in which the child page resides is called 'plugins', this folder name is embedded in the link, which gives an apparent missing single quote
...frustratingly,
if I add a backslash, i get the site root (as expected) on both parent and child pages
if i add a folder name, i get the folder name on both parent and child pages
the problem demonstrated only occurs if i leave the value blank
where the child page is fine, but the parent page gives the error
When loading the Parent page the browser's console shows this error:
This is a Javascript error. The problem is that line 170 has improper Javascript syntax. The single quote is missing. This has nothing to do with Datatables. You will need to look at the code that is generating the Javascript to determine why it is not providing proper Javascript syntax when it is adding the folder
plugins
.Kevin