4

I am trying to have my document library views show indicators next to documents based on the values of certain fields. I have spent considerable time trying to find a solution using JSLink but it seems the field must be in the view for the Javascript to call the value. I want the indicators to work regardless of which fields are in the view. Does anyone have any suggestions as to how I could achieve this? In SP2010 I could use conditional formatting to achieve this but SP2013 has removed this and I am not a big fan of writing a custom xsl template, unless that's my only option.

I have considered creating a calculated column as well which holds the values of all the fields I want indicators for separated by a special character and having the JSLink render the item based on this value, and then hiding that column, but this does not seem like a good solution.

  • Well, JSLink is in much dependent on that the field you want to get information from is in the view somehow, as ViewField, query or so. Otherwise it will not be added to the ctx. Off course you could get it with CSOM on render, but that would be very expensive. – Robert Lindgren Dec 19 '13 at 6:59
  • Why not override the entire view instead of the field? That way you can simply not display the field, yet still call it in the view. – wjervis Jun 26 '14 at 11:02
1

To get access to fields that are not in your current view, you can make a REST call to that particular list/element. Load up a script editor and try the following:

$(document).ready(function(){
   $.ajax({
        url:"https://sharepointsite/_api_/web/lists/GetByTitle('Yourlibraryname')/items",
        type:"GET",
        headers:{
            "accept":"application/json;odata=verbose"
        },
        succes:function(data){
            //Loops over each item
            $.each(data.d.results,function(index,item){
                if (item.yourvalue != null){
                    // It exists and you can do stuff.
                }
            }
        },
        error:function(error){
            alert(JSON.stringify(error));
        }
    });
});

The script makes a call to the api after page is loaded and on success it will grab all the returned data and drill down.

As you see there an if inside the each loop, that checks if your listitem has a value.If its true, i.e. the value is not null, you can do things like display your statusindicator or wrap the value in a color etc. Hope that helps.

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.