0

we need to create single jslink file for 2 same list view webparts configured on the same page

here are the rendering rules that is defined

  1. First Webpart should have some columns to be shown/some columns should be hidden
  2. Second Webpart should have some columns to be shown/some columns should be hidden.

we found out something like this for conditional rendering ctx.wpq== "WPQ3"

how can we render the view with such condition any help would be appreciated?

1
  • Can't you create two different js files and add those in JSLink property of each list webpart? And then hide columns according to your need. Jul 17, 2019 at 13:08

1 Answer 1

0

Sample demo for your reference.

<script type="text/javascript">
    (function () {

        var overrideCtx = {};
        overrideCtx.Templates = {};
        overrideCtx.Templates.OnPostRender = CustomRender;

        SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);

    })();
    function CustomRender(inCtx) {
        if (inCtx.wpq.indexOf("WPQ3")) {
            $('table.ms-listviewtable th:nth-child(4)', '#MSOZoneCell_WebPart' + inCtx.wpq + '').hide();
            $('table.ms-listviewtable td:nth-child(4)', '#MSOZoneCell_WebPart' + inCtx.wpq + '').hide();

        }
        else {
            $('table.ms-listviewtable th:nth-child(5)', '#MSOZoneCell_WebPart' + inCtx.wpq + '').hide();
            $('table.ms-listviewtable td:nth-child(5)', '#MSOZoneCell_WebPart' + inCtx.wpq + '').hide();
        }
    }
</script>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.