2

I have a long formula which I put into the formula field in the calculated column. However, in Sharepoint 2013, the text in formula field is not wrapped. Is there anyway to make the text wrapped in this case?

Formula Field

0

I interpreted your question in two different ways:

.

1 - output a linebreak in a View

You have 2 options in SharePoint 2013 to format output of the Calculated Column

Calculated Column with HTML

You can make a Calculated Column output as HTML/JavaScript by setting the datatype to Number. Change your Formula to include an HTML BReak and you are done

=TRIM(LastName)&"<br>"&TRIM(FirstName)

Pros

  • Works everwhere the Column is displayed
  • Also works in SharePoint 2010

Cons

  • Only works in Views
  • The bare HTML is displayed in other places like Forms, Alerts

Full detailed explanation of using HTML & JavaScript in a Calculated Column at http://www.viewmaster365.com/#/How

Client Side Rendering of a Column

Since SharePoint 2013 you can use CSR and JSlink to completely change the user interface.

CSR is your JavaScript override which make all the changes, JSlink is the method where you have to tell every View, Form, Field, Webpart which CSR file it has to use.

For your simple linebreak this 'simple' Javascript file (saved in ~site/Style Library/myCSR.js) will do:

(function () {
    var CSRcontext = {};
    CSRcontext.Templates = {};
    CSRcontext.Templates.Fields = {
        "firstName": {
            "View": myCSRTemplate
        }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(CSRcontext);
})();
function myCSRTemplate(ctx, CurrentFieldSchema, CurrentItem, ListSchema) {
    var firstName = CurrentItem[CurrentFieldSchema['firstName']].trim();
    var lastName = CurrentItem[CurrentFieldSchema['lastName']].trim();
    return firstName + "<BR>" + lastName;
}

And you have to assign the JSLink path ~site/Style Library/myCSR.js to **every* View you want this executed.

The Major drawback is you also (unlike the first Formula option) have to include firstName and lastName in the View, otherwise those Columns are not available in the CSR file. (You can ofcourse do the work in the Calculated Column like you do now then use CSR to make it output as HTML)

2 - You want line breaks in the Formula textarea

I reread you question..

If you mean you want to wrap the text inside the TextArea while editting you have several options:

switch to Chrome Browser

In Chrome TextArea has a resize handle.

Assign CSS to the textarea

If you can get into your MasterPage (or other CSS file) just add:

#onetidIODefTextValue1{
    white-space: pre;
}

Again, easier on Chrome, where you can use the StyleBot plugin to apply this CSS on the fly.

Or you can create your own Bookmarklet (a Favorite button in your browser which execute JavaScript).
Goto MrColes BookMarklet Creator and paste the script:

document.getElementById('onetidIODefTextValue1').style.whiteSpace="pre";

Drag the blue (this link) to your Favourites bar (and rename it)

Now on any Formula page you can execute the BookMarklet.

CalcMaster

If you are comfortable adding a Bookmarklet with more JavaScript.

I have written a small 'CalcMaster' bookmarklet which hooks into the formula-editor and does a save of the Formula on every keypress; giving immediate feedback.
Recently published a first version on GitHub:

https://github.com/Danny-Engelman/CalcMaster

|improve this answer|||||

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.