0

On my intranet, developed with SharePoint 2013, I have a WebPart for Announcement.

People who makes Announcement have no text limit for that, but I would like to limit it at 3 lines the text on view.(to see the complete Announcement, people have to click on the hyperlink Title)

I have tried to add a calculated column which return the body column but limited to 200 character.

I didn't found this kind of formula.

Is there another solution for limiting the view to 3 lines instead of the entire Announcement?

1 Answer 1

0

you can use JSLink to trim down the body of the announcement. Basically, you will have to create a js file and put your logic there!

Here are couple of links on how to use JSLink to alter the UI of a list

http://www.idubbs.com/blog/2014/js-link-highlighting-a-row-with-csr/

http://jsuhail.blogspot.com/2014/09/client-side-rendering-using-jslink-post_30.html

your logic in the js file will be something similar to that :

(function () { 

    // Create object that have the context information about the field that we want to change it's output render  
    var bodyFieldContext = {}; 
    bodyFieldContext.Templates = {}; 
    bodyFieldContext.Templates.Fields = { 
        // Apply the new rendering for Priority field on List View 
        "bodyField": { "View": bodyFieldTemplate } 
    }; 

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFieldContext); 

})(); 

// This function provides the rendering logic for list view 
function bodyFieldTemplate(ctx) { 

    var body = ctx.CurrentItem[ctx.CurrentFieldSchema.body];

    var bodyHTML="";
    if (body.toString().length > 250) {
            bodyHTML = body.toString().substring(0,250) + "...";
        }

    return bodyHTML;
}
4
  • in your above code example. I guess view is the name of the sps list?
    – Jason
    May 17, 2016 at 22:28
  • If yes, where to provide detaila of the specifc column wherein we want to length of trxt.
    – Jason
    May 17, 2016 at 22:29
  • got it view here is the default view form. But not sure yet on the column that needs attention.
    – Jason
    May 17, 2016 at 23:31
  • I have gone through your code example and thanks for it. I`ve added the code with the required modification to show eclipse (...) for more than 250 characters for Field name: msg under List view name: AllIItems. (List name: msgworld) // update by Jason: name of the field: msg and view name : AllItems "msg": { "AllItems": bodyFieldTemplate }
    – Jason
    May 17, 2016 at 23:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.