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 Answer 1

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>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.