Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
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 Jul 20 '12 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 Jul 20 '12 at 14:33

2 Answers 2

up vote 0 down vote accepted

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.

share|improve this answer
    
Nice. That was what I was looking for. Works perfectly. –  Jeffrey B. Murphy Feb 19 '13 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 ...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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