Below is the full code for client side rendering of List View Webpart:


(function () {  
    var overrideCurrentContext = {}; 
    overrideCurrentContext.OnPreRender = hideRows;
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);        
 })();
 function hideRows(ctx) {  
    var rows = ctx.ListData.Row;
    //Hide whole list based on condition    
    if(masterlistarr.indexOf(currentUser) == -1){
        //user not in master list
        console.log("no access");
        $('#ctl00_PlaceHolderMain_WikiField').before("<div style='height:40px;border:1px solid #AEAEAE;position:relative;text-align:center;color:red;font-weight:bold;padding:20px;'>Access Denied<br>You don't have access please contact Admin!</div>");
        $(ctl00_PlaceHolderMain_WikiField).hide();               
    }

//following code used to disable oob list filter and hide 'new item' feature

    else{
//following code used to disable oob list filter and hide 'new item' feature
        if(count == 0){
            $('.ms-headerSortArrowLink').hide();
            $("div.ms-vh-div").attr("filterdisable", "TRUE");
            $('#idHomePageNewItem').get(0).nextSibling.remove();
            $('#idHomePageNewItem').hide();    
        }
        count++;
// compare specific column value eg."TeamleadFullName" which is of type People and Group and hide rows based on that
        for (var i = 0; i < rows.length; i++) {
            var curTL = rows[i]["TeamleadFullName"][0].email.toLowerCase();
            if(curTL !== currentUser){
                // return '';  
                var rowId = GenerateIIDForListItem(ctx, rows[i]);
                var row = document.getElementById(rowId);
                // row.style.display = "none";
                row.parentNode.removeChild(row);                                                                              
            }                        
        }       
    }     
}

hope this helps

0

There are 0 answers