1

I have a JSLink text field that overrides the View template. It stores a few delimited values that it parses into an anchor tag:

Field Working

If I delete one row, the other rows no longer display the view template, it displays the raw data for them instead:

Field Not working

What can I do to prevent this from happening?

  • Is the MDS feature enabled on that site? – Dylan Cristy Aug 3 '15 at 14:14
  • The MDS Feature is enabled on the site – Snowburnt Aug 3 '15 at 17:11
4

This is possibly due to the fact that MDS is enabled on your site. When MDS is enabled, you have to take a couple extra steps when setting up your Client Side Rendering scripts so that they are not bypassed by the MDS engine.

Specifically, instead of having all your CSR override code wrapped in an anonymous self-executing function, you need to provide a named entry point to register with the MDS engine so MDS knows to always execute your code. You do that by calling RegisterModuleInit() with the path to your script file, and the name of the entry point function.

In your case you may need to do something like this:

myNamespace = myNamespace || {};

myNamespace.myFieldOverride = {
    customField: function (ctx) {
        var fieldHtml = "";
        // do whatever processing is necessary
        // here to generate the custom html
        return fieldHtml;
    },
    render: function () {
        var overrideCtx = {};
        overrideCtx.Templates = {};
        overrideCtx.Templates.Fields = {
            "Autocomplete Field": {
                View: myNamespace.myFieldOverride.customField
            }
        };

       SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
    }
};

// register for MDS enabled sites,
// obviously use the correct path to your script file here
RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~site/SiteAssets/Scripts/myOverrideScript.js"), myNamespace.myFieldOverride.render);

// fallback for non-MDS enabled sites
myNamespace.myFieldOverride.render();

Here is a blog post also about registering CSR scripts with the MDS engine.

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.