Dear all,
within the view of a SharePoint 2013 document library, I show these two columns (amongst others):
- LinkFilename - "Name (linked to document with edit menu)", e.g. "filename1"
- Title, e.g. "This is my title of interest"
I want to replace the text of the LinkFilename column with the value of the title column so that I can remove the title column.
Background:
The filename itself is of no interest for the users, only the title is. But the title has neither a link to the file nor an edit menu.
My Approaches:
When using the following JS using JSLink I managed to replace the text, but also the link to the file was gone (obviously):
(function () { var overrideNameField = {}; overrideNameField.Templates = {}; overrideNameField.Templates.Fields = { "LinkFilename": { "View": overrideNameFieldTemplate } }; SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideNameField); })(); function overrideNameFieldTemplate(ctx) { var title = ctx.CurrentItem.Title; ctx.currentItem return title; }
The second approach was overriding the title column with the link to the file.
Unfortunatlely this lead to the issue, that the IE dialogue "Open Document" (How would you like to open this file: Read Only / Edit) did not show up (and all Office files would open in read-only mode).
(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>"; } }
I prefer a solution with JSLink (client-side rendering).
Any help is appreciated.
TIA