1

I need to run some jQuery (some formatting clean-up) against the output of an OOTB list which is loaded and refreshed with ajax. The problem is that the list doesn't render until well after jQuery's ready function fires. Is there some kind of callback function I can hook into? I have a similar issue with other web parts. It seems like SP would have made this possible, considering how must customization requires JavaScript, but I can't for the life of me find the solution.

1

I've used a technique like this in the past to handle the execution of jQuery after webparts ajax load or ajax refresh, https://stackoverflow.com/a/7062485/318776. Basically after the ajax call/postback is complete, it will execute your code.

<script type="text/javascript">
            Sys.Application.add_init(function () {
                Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
            });
            Sys.Application.add_init(function () {
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
            });

            function BeginRequestHandler(sender, args) {
                AsynProcessing('block', 'AlertDiv', 'ProcessingImage');
            }
            function EndRequestHandler(sender, args) {
                AsynProcessing('none', 'AlertDiv', '');
            }
            function AsynProcessing(visstring, elem, img) {
                var adiv = $get(elem);
                adiv.style.display = visstring;
                adiv.image = img;
            }  
            </script>
  • Thanks for the response. What is the required script file for this to work? I can't seem to get the alert to fire no mater how I arrange the JS. I've tried making the Sys.WebForms requests by themselves, inside "ExecuteOrDelayUntilScriptLoaded", inside "Sys.Application.add_init()" - as shown here, and inside jQuery's ready function. There must be something obvious I'm missing... – Rob Wagner Aug 29 '14 at 20:49
  • Ok, so maybe I was looking for the wrong thing in my initial tests. @PirateEric's code will trigger when I click on a heading in the list web part to sort, but it does not trigger when the web part loads the first time. – Rob Wagner Sep 2 '14 at 15:12

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.