Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 7025

Deprecated: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 2162

Deprecated: Hook imagify_allow_picture_tags_for_webp is deprecated since version 2.2! Use imagify_allow_picture_tags_for_nextgen instead. in /www/collab365_296/public/wp-includes/functions.php on line 5758
How to: JSLink, show multiple people field on a tooltip. - Collab365
Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Deprecated: strstr(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1145

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1152

Deprecated: stripos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1155

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1162

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /www/collab365_296/public/wp-includes/functions.php on line 1165

Warning: Undefined array key "url" in /www/collab365_296/public/wp-content/plugins/thrive-visual-editor/thrive-dashboard/inc/smart-site/classes/class-tvd-smart-shortcodes.php on line 85

2014-10-08

Perhaps one of the most useful features within Sharepoint 2013 are Display Templates  (aka. CSR or JSLink).

In my current scenario, I have a list called “projects” with a field called “Project Team”, this field is is Multiple People Field, and by default sharepoint renders in the list views with one new line per person.

This can be very annoying, especially if you have 100 people in your field value.

How to fix this? At least for my scenario, I can join all values together and put them on a tooltip.  Code is below and I consider it to be self explanatory.

(function () { 

// Create object that have the context information about the field that we want to change it's output render 
var projectTeamContext = {}; 
projectTeamContext.Templates = {}; 
projectTeamContext.Templates.Fields = { 
// Apply the new rendering for Body field on list view 
"Project_x0020_Team": { "View": ProjectTeamTemplate } ,
}; 

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(projectTeamContext); 

})(); 


// This function provides the rendering logic 
function ProjectTeamTemplate(ctx) { 

var projectTeamValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name]; 

//newBodyvalue should have the list of all display names and it will be rendered as a tooltip automaticlaly
var bodyValue = projectTeamValue.map(function(person) {
return person.value;
}).join(", ");

var newBodyValue = bodyValue; 

if (bodyValue && bodyValue.length >= 100) 
{ 
newBodyValue = bodyValue.substring(0, 100) + " ..."; 
} 

return "<span title='" + bodyValue + "'>" + newBodyValue + "</span>"; 

}

 

Originally posted here:

http://www.luisevalencia.com/2014/10/07/how-to-jslink-show-multiple-people-field-on-a-tooltip/

(Visited 142 times, 1 visits today)

About the author 

Luis Valencia

Summit Bundle

Get 200+ hours of Microsoft 365 Training for 27$!

Master Office 365, Power Platform & SharePoint & Teams With 200+ Hours Of Training Videos and 108 Ebooks in the Collab365 Academy. This offer is insane and is only available for a limited period.