1

I've a list with fields field1 and field2. In one view I would like to append the value of field2 to field1 and hide field2.

Is that possible with JSLink? How can I do that?

5
  • Don't fall in the Programmers-Trap, standard Calculated Columns as Amal answered is what you need – Danny '365CSI' Engelman Apr 29 '15 at 18:19
  • I have to change more than just appending one column to another. My questions was just simplified to get started. – jlai Apr 30 '15 at 6:38
  • What do you want to do? Calculated Column Formulas are under-valued – Danny '365CSI' Engelman May 3 '15 at 10:27
  • @DannyEngelman I also want to add some formatting, bold title, special format for internal number systems, etc. – jlai May 4 '15 at 7:19
  • 1
    doable; see ViewMaster365.com/#/How – Danny '365CSI' Engelman May 5 '15 at 8:03
0

If you want to do this solely using the JavaScript in your JSLink file, it can be done by concatenating the value of both fields, then replacing field1's value with the concatenated value. The tricky part will be hiding field2.

You can hide the cell containing field2's value using injected CSS, but you'll end up with a blank column because of the headers. Therefore you'll also need to inject CSS that hides the header cell as well. And, since all of this is dynamically built by SharePoint on the fly (and not necessarily in a logical way), you may end up with a screwy table mess on your hands.

Then again, the great thing about JSLink functionality is that you can easily remove or alter the file without actually modifying your view. So feel free to play around with different code until something works. The code below is off the top of my head, so it probably won't work right off the bat, but it should get you going in the right direction:

//----------------------------------------
// Overrides the value of the Name field
//----------------------------------------

(function () {
    var overrideCtx = {};
    overrideCtx.Templates = {};
    overrideCtx.Templates.Fields = {
        'Name': { 'View': renderNameLink }
    };
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
}) ();
function renderNameLink(ctx) {
    var itemFirstName = ctx.CurrentItem["Name"];
    var itemLastName = ctx.CurrentItem["FirstName"];
    var itemID = ctx.CurrentItem["ID"];     
    var html = "";
    html += "<a style='height:16px; vertical-align:top;' href='#' onClick='javascript:OpenPopUpPage(&quot;/site/Lists/Contacts/View.aspx?ID=" + itemId + "&amp;IsDlg=1&quot;, null, 850, 800);'>";
    html += "" + itemFirstName + " " + itemLastName + "";
    html += "</a>";
    return html;
}

That will get the concatenated value, but you still have to inject CSS to hide the second field column.

3

You can easily do this by introducing a Calculated Field.

  1. Create a new Calculated field and use Formula

    =[Field1] & [Field2]
    

Now modify you View and add the new Calculated Field and Remove Field2

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.