Question

I have the folloing definition in my schema.xml

 <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" 
            DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/15/images/generic.png?rev=23" 
            Url="AllItems.aspx">
        <Toolbar Type="Standard" />
        <XslLink Default="TRUE">main.xsl</XslLink>
           <JSLink>~site/_Layouts/15/BookManagement/Scripts/Booking.List.CSR.js</JSLink>
        <RowLimit Paged="TRUE">30</RowLimit>
        <ViewFields>
          <FieldRef Name="Nr" />
          <FieldRef Name="LinkTitle" />

The references skript includes the following:

(function () {

    // Create object that have the context information about the field that we want to change it's output render  
    var bodyFiledContext = {};
    bodyFiledContext.Templates = {};
    bodyFiledContext.Templates.Fields = {
        // Apply the new rendering for Body field on list view 
        "Nr": {
            "View": FormatToString
        },
        "Auflage": {
            "View": FormatToString
        },
        "Erscheinugsjahr": {
            "View": FormatToString
        },
        "DoWarning": {
            "View": DisplayWarningbutton
    }
};
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(bodyFiledContext);

})();


function DisplayWarningbutton(ctx) {
    var bodyValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
    var url = _spPageContextInfo.siteAbsoluteUrl; 
    url = url + "/_layouts/15/BookManagement/DoWarning.aspx?ID=" + ctx.CurrentItem.ID + "&List=" + ctx.listName + "&TemplateID=b336e092-4722-442d-b189-5c0ca3a65888";
    return "<a href='" + url + "' >Klick me</span>";
}

// This function provides the rendering logic 
function FormatToString(ctx) {

    var bodyValue = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
    bodyValue = bodyValue.replace(".", "");
    return "<span >" + bodyValue + "</span>";

}

Now when my page loads and I go to the specified View, the JSLink script will not be executed. When I reload the Page by pressing F5, the script will be executed.

Is there a detail what I am do wrong?

Was it helpful?

Solution

I guest your site has MDS feature (a.k.a Minimal Download Strategy) enabled (that is enabled by default), which causes this behavior. When you navigate to view directly not all JavaScript is runned and only MDS registered modules is executed. On the other hand, when you press F5, whole page is reloaded and all JS files are executed.

To solve this you have two options:

  1. Disable MDS feature on the site. It is probably the easiest and fasted solution.
  2. Register your script to execute as MDS module. Here is very amazing solution, that works very well: Register CSR-override on MDS enabled SharePoint 2013 site.

OTHER TIPS

I see the question is some years old, but I'd like to shere two nice CSR tutorials anyway:

  1. About ListViews
  2. About ListForms
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top