0

Using jqGrid 4.5.2 & jQuery 1.9.1 and reading an XML file as input into a grid. One cell has a path that points to a file. That file may be of several different types (.doc, .htm, .pdf, etc.).

In displaying the grid, I need to have that cell be a hyperlink to that file share. Using the predefined format type of link, it does provide a hyperlink to it, but it puts the web server info in front of the link, such as:

http://localhost:55555/\\servername\filepath1\filepath2\thisdoc.doc

Everything from the \\ on is retrieved from the XML. How do you make the contents of the cell a hyperlink, but suppress the website info?

steve_o
  • 1,243
  • 6
  • 34
  • 60

1 Answers1

0

I would write a custom formatter for it, like this one:

var urlFormatter = function (cellValue, options, rowObject) {
    return '<a href="' + cellValue + '">' + cellValue + '</a>';
};

This way the result should be:

<a href="servername\filepath1\filepath2\thisdoc.doc">
    servername\filepath1\filepath2\thisdoc.doc
</a>

Update:

I did not realize it was a filesystem URL. In that case modify it like this:

var urlFormatter = function (cellValue, options, rowObject) {
    return '<a href="file:///' + cellValue + '">' + cellValue + '</a>';
};

Which yields:

<a href="file:///servername\filepath1\filepath2\thisdoc.doc">
    servername\filepath1\filepath2\thisdoc.doc
</a>

This should work. The reason because it did not work previously was that the browser interpreted the link as a relative link, but you wanted a absolute link to a part of the filesystem.

meskobalazs
  • 15,741
  • 2
  • 40
  • 63
  • I have that function now in the formatter of the colModel. The cellvalue is correct, but if you mouseover the link, it still has the http://localhost/55555/ before the file path & returns a 404 Not Found error if you right click & open in a new tab. – steve_o Feb 10 '15 at 18:07
  • Wait, servername is actually a domain? – meskobalazs Feb 10 '15 at 18:15
  • It is a file share, where those various documents (pdf, htm, doc, etc) are located. In the grid it looks right. I put a console.log statement to dump the cellvalue out & it looks right also. But, when you mouseover the link, it's got the "http://localhost:55555/" before the filepath (\\servername\filepath1\filepath2.....). – steve_o Feb 10 '15 at 18:21
  • I made the change, but had to put one more slash (/) in the file: portion of the URL. I can copy the link & paste it in a new window and it will open, but can't right-click on the link (or click on it) to make it open. – steve_o Feb 10 '15 at 20:18
  • Well, this is the best you can get: http://stackoverflow.com/questions/18246053/how-can-i-create-a-link-to-a-local-file-on-a-locally-run-web-page – meskobalazs Feb 10 '15 at 20:24