I have an external list that I want to hackup with jQuery. If i put a simple alert in document .ready, it fires, and THEN the SharePoint progress spinner shows up, and then the data is returned - long after document.ready. Has anyone been able to use jQuery to manipulate the results of a SharePoint external list? I hope that makes sense.
- The BCS data itself is being retrieved via Ajax / javascript, so it makes sence document.ready fires before the data is actually there. You could look into the way SharePoint loads this data and replicate it on a custom page of your own; that way you should be able to fire your custom functions after the data loads. Perhaps there's even a client side event to subscribe to, don't know though.Jasper– Jasper2012-07-20 10:06:43 +00:00Commented Jul 20, 2012 at 10:06
- Jasper, I looked high and low to find way to intercept that event, but was unsuccessful. If someone finds a way to do this, that would be a better solution that the one I proposed, which is clunky but at least works.Derek Gusoff– Derek Gusoff2012-07-20 14:33:50 +00:00Commented Jul 20, 2012 at 14:33
2 Answers
I ran into this problem as well. You have to do periodic polling of the DOM to detect when the content is loaded. What I implemented looked something like this:
$().ready(function () { checkForDOMAndCalculate(); }); function checkForDOMAndCalculate() { setTimeout(checkDOM, 100); } function checkDOM() { displayValueIndex = $("tr.ms-viewheadertr.ms-vhltr th a:contains('DisplayValue')").closest("th").index(); approvalStatusIndex = $("tr.ms-viewheadertr.ms-vhltr th a:contains('ApprovalStatus')").closest("th").index(); if (displayValueIndex == undefined || displayValueIndex == -1) { checkForDOMAndCalculate(); } else { doCalculations(); } } Here's what the code does: it delays for 1/10 of a second, looks for a particular value in the DOM using jQuery, and if it finds it, proceeds with the calculations. If it doesn't find it, it waits another 1/10 second and tries again. It repeats this until it finds the DOM has loaded.
The key to this is the setTimeout() function, which executes the delay and then the code.
- Nice. That was what I was looking for. Works perfectly.Jeffrey B. Murphy– Jeffrey B. Murphy2013-02-19 22:56:39 +00:00Commented Feb 19, 2013 at 22:56
I would recommend you to check the SPServices, it is Client Object Model ... check msdn for that. I think with that you can manipulate the data on the client side and then probably pass to your own JQuery functions etc ...