0

I found this script, see below, which converts the XML format generated from the repeated section within a sharepoint list and renders it in HTML format.

<script type="text/javascript">  
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({  
  Templates: {  
           Fields: {  
                'CashOverview': {   
                    'View': repeatingSectionViewTemplate  
                 }  
           }  
  }  
});  

function repeatingSectionViewTemplate(ctx) {  
   var xml = ctx.CurrentItem["CashOverview"];  
   var decodedxml = xml.DecodeXMLNotation();   
   var htm = "";  

   xmlDoc = $.parseXML( decodedxml );  
   $xml = $( xmlDoc );  
   $xml.find("Item").each(function() {  
      htm = htm + "<tr><td>" + $(this).find("Test").text() +"</td></tr>";  
   });  

   return "<table border='1' width='500'><tr><th align='left'>Test</th></tr>" + htm +"</table>";  
};  

//Replaces html notation to their equivalent xml escape characters.  
String.prototype.DecodeXMLNotation = function () {  
    var output = this;  
    if ($.trim(output) != "") {  
        output = output.replace(/&apos;/g, "'").replace(/&quot;/g, '"').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&');  
    }  
    else {  
        output = "";  
    }  
    return output;  
};  

</script>

enter image description here

However, this only works when the sharepoint style is set to "Default"
When changing the style to "Basic Table" then it won't work.

Makes me wonder if there is something within the script to be added?
Any ideas, suggestions?

Thanks

Your Answer

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

Browse other questions tagged or ask your own question.