0

hope you're well;

What is javaScript code to add on SharePoint list for showing a few lines of text per row so they all the same size where reams of text have been written this is via scroll or expand arrow can it be applied to all views. enter image description here

0

You could probably use JSLink and create a substring of the text in that field.

As an example this is what i'm using to modify list view fields before they are loaded (a simple STATUS color based on what is selected).

var statusFieldCtx = {};

statusFieldCtx.Templates = {};
statusFieldCtx.Templates.Fields = {
    "Status": {
        "View": StatusFieldViewTemplate
    }
};

SPClientTemplates.TemplateManager.RegisterTemplateOverrides(
    statusFieldCtx
    );

And then i'm using something like this to append values.

function StatusFieldViewTemplate(ctx) {
var _statusValue = ctx.CurrentItem.Status;

if (_statusValue == "New") {
    return "<span class='statusSpanJS' style = 'background-color: #BDD7EE; padding: 5px 0px 8px 5px; display: block; height: 100%; width:100%;'>" + _statusValue + "</span>";
}

Based on that code you could get the field that you need to trim and use substring.

You can read more -> https://www.c-sharpcorner.com/article/modify-sharepoint-list-view-using-client-side-rendering-and-jslink/

https://social.technet.microsoft.com/wiki/contents/articles/37203.sharepoint-online-customize-list-view-web-part-using-jslink.aspx

https://www.w3schools.com/jsref/jsref_substring.asp

By using substring you would simply limit the appended value to like 100 (therefore all of the items will be of equal length/size).

  • Would I need to add this code to content editor web part and apply it onto the page. – AY_91 Jul 20 '18 at 10:11
  • That code goes into the webpart of the list view. Edit it and at the bottom you'll have an option to add "JSLink". Edit: check the first link i ref'd, its not exactly what you are looking for, but it shows how to add it. – Dante R. Jul 20 '18 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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