JSLink is the greatest thing since sliced bread. Not.
There are some weird issues concerning standard stuff and I'm not sure whether these are limitations or I'm doing something wrong.
I want to have the document's title as a clickable link, not the file name. This is more beautiful considering file names such as AB2929329.pdf and a title of Joeys Earnings.
A document library list view and JSLink makes this very easy:
(function () {
var overrideNameField = {};
overrideNameField.Templates = {};
overrideNameField.Templates.Fields = {
"Title": { "View": overrideNameFieldTemplate }
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideNameField);
})();
function overrideNameFieldTemplate(ctx) {
var title = ctx.CurrentItem.Title;
var fileRef = ctx.CurrentItem["FileRef"];
var fileLeafRef = ctx.CurrentItem["FileLeafRef"];
if (title) {
return "<a href='"+ fileRef + "'>"+ title + "</a>";
}
else {
return "<a href='"+ fileRef + "'>"+ fileLeafRef + "</a>";
}
}
That was easy, wasn't it? The title field now always is rendered as a link - if the title is not set the default FileLeafRef is taken. This works as long as you have the FileLeafRef field also in your view or the icon (icon is fine).
I'm greedy. I not only want the title to be the link to the document, I also want the menu (...) to have a preview of the file when clicking on it via Office Web Apps. Just like FileLeafRef renders: "Filename ..." and you have all the actions on the "...".
So, all I have to do is replace "Title": { "View": overrideNameFieldTemplate }
with "LinkFilename": { "View": overrideNameFieldTemplate }
in the above code. Boom it works! But here comes the kicker:
It only works when I have the Title
field on my list view. When I remove the field ctx.CurrentItem.Title
is null. When I add the field back to the view it exists.
How can I achieve to have a clickable title of a document as well as the document menu (...)? I would love to use JSLink, but wouldn't mind using XSLT even though it has become impossible to create with the changes in SharePoint Designer 2013.
"Title": { "View": overrideNameFieldTemplate }
?ListItemMenu
sounds good! Any idea how I could change it without deploying a custom list definition? SharePoint Manager? @PaulSchaeflein Bummer... Didn't know that.ListItemMenu
unfortunately does not provide document previews, but the real menu.CalloutMenu=TRUE
Awesome! Please post an answer wjervis