1

I wrote a custom onclick event for a class in jquery, I have attached the script with JS link of listview web part. There is default paging in the listview web part. In first page the click event works perfectly but after navigating to the other pages the click event is not triggering.Any help would be helpful. thanks in advance. Sample code is given below:

$(document).ready(function () {  
    $('.ms-listlink').bind('onclick', function (e) {  
        var documentURL = $(this).attr('href');  
        var url = "https://Test.sharepoint.com/sites/TestSite/SiteAssets/TestPage.aspx?URL=" + documentURL;  
        $(this).attr('href', url);  
    });  
});  
1

Try to inject your jQuery logic in OnPostRender of JSLink.

<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
        (function () {
            function OnPostRenderTemplate(ctx) {
                $(document).ready(function () {
                    alert('DOM ready');
                    //
                    $('.ms-listlink').bind('onclick', function (e) {
                        var documentURL = $(this).attr('href');
                        var url = "https://Test.sharepoint.com/sites/TestSite/SiteAssets/TestPage.aspx?URL=" + documentURL;
                        $(this).attr('href', url);
                    });
                });
            }

            function RegisterListViewTemplate() {
                var viewContext = {};
                viewContext.Templates = {};
                viewContext.Templates.OnPostRender = OnPostRenderTemplate;
                SPClientTemplates.TemplateManager.RegisterTemplateOverrides(viewContext);
            }
            ExecuteOrDelayUntilScriptLoaded(RegisterListViewTemplate, 'clienttemplates.js');
        })();
    </script>

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.