List view web parts are very useful to show the summarize information for the lists and user can easily walk through all list items in quick glance. Normally we keep columns with smaller values in list view like Title, date, status, type and priority etc. to have user friendly view of the list. But sometime we get the requirement to show lists with images or multiline text fields to get more detail on list view page instead of going to list item detail. Sometime this result in unreadable output with long vertical scroll on the page.
To minimize this effort, I am sharing a JSLink script and its integration detail to trim the multiline text field and show the text in tool tip instead on the page.
Below is a simple script which you can save in SharePoint’s siteassets or any other document library:
(function () { var priorityFiledContext = {}; priorityFiledContext.Templates = {}; priorityFiledContext.Templates.Fields = { "Project_x0020_Notes": { "View": bodyFiledTemplate } }; SPClientTemplates.TemplateManager.RegisterTemplateOverrides(priorityFiledContext); })(); function bodyFiledTemplate(ctx) { var bodyValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; //This regex expression use to delete html tags from the Body field var regex = /(<([^>]+)>)/ig; bodyValue = bodyValue.replace(regex, ""); var newBodyValue = bodyValue; if (bodyValue && bodyValue.length >= 100) { newBodyValue = bodyValue.substring(0, 100) + " ..."; } bodyValue = bodyValue.replace(/'/g, " "); return "<span title='" + bodyValue + "'>" + newBodyValue + "</span>"; }
Below are steps to integrate JSLink file on a list view webpart:
- Edit the list view page, this will show the list web part in edit able mode.
- Open the web part properties for list view web part.
- Scroll down and expand the Miscellaneous node and enter the url of JSLink file as shown in below screenshot
- Press Ok to save the changes, and then save changes on the page and you can see output similar to below screenshot which showing trimmed multiline text field and it’s full detail in tool tip.
I just rich text field to show output as plan text, you can also play with the css for a better look n feel for the tooltip.
No Comments