I have an external list with one field/column that contains an URL and title.
e.g. "http://www.example.com/somefile.ext
,Example file"
But since I want to just show a hyperlink with the title I've written this to render the field in a listview:
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
'LinkToFile': { 'View': renderFileLink }
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();
function renderFileLink(ctx) {
var fieldVal = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
var value = fieldVal.toString().split(',');
var html = "<a href='" + value[0] + "' style='white-space:nowrap;'>" + value[1] + "</a>";
return html;
}
When I edit the page, go to webpart properties and type in the URL to the js file ~site/siteassets/jsfile.js
and hit apply the page refreshes and the field is rendered correctly. I then stop editing the page and save it and the field is no longer rendered correctly but instead I just get the value "http://www.example.com/somefile.ext
,Example file". If I then again edit the page and go to webpart properties for the listview the jslink still contains the correct URL and I can again click apply and the custom formatting is applied to the view, but again when I save it stops working.
The script loads and when I debug the page it goes into renderFileLink
for every item in the list but when the items are displayed nothing has been changed.
Has anyone encountered anything like this and knows a solution or have ideas for things I can try to fix this?
UPDATE: I'm now getting closer to finding a solution. It seems the first column of the view gets the three dots to open the menu for the item and because of that I'm unable to apply the custom rendering to the field. As soon as I added a new field and had that first in the view and LinkToFile field second then my script renders the field correctly.
So my new problem is the first field. Is there a way I can specify what field is the title field (the one that has the ... menu associated with it) so that I can just leave that out of the view and only have my other column (LinkToFile) without it getting the ... menu?
UPDATE: I was unable to find a solution to the problem. Instead I ended up hiding the first column with css.
~
?