How to use aop.js with jQuery on Grouped Lists?
<p>This question came from following up on an <a href="http://sharepoint.stackexchange.com/questions/16407/how-to-make-grouped-view-work-with-the-document-ready-event">answer given here</a>.</p>

<p>I want to use jQuery to work css modifications on a list that has grouping.  <a href="http://sharepoint.stackexchange.com/questions/16407/how-to-make-grouped-view-work-with-the-document-ready-event">I discovered</a> a <a href="http://code.google.com/p/jquery-aop/" rel="nofollow">jQuery script called <code>aop.js</code></a> that will allow you to attach function calls onto other functions.  There is <a href="http://www.sharepoint-howto.com/2011/12/20/sharepoint-aspect-oriented-programming-aop-with-jquery/#comment-14622" rel="nofollow">another page here</a> with more explanation.  And so, I came up with this, where I attach a function call onto <code>ExpGroupRenderData</code> so that I can run a function AFTER the list items are grouped.</p>

<pre><code>jQuery.aop.around( {target: window, method: 'ExpGroupRenderData'},
    function (invocation) {
    //alert("args2=" + invocation.arguments[2] ");
        if (invocation.arguments[2] == 'true') { //check to see if html loaded
            var group = "#tbod"+invocation.arguments[1]+"_";    //the invocation gets the main groupname, something like tbod40-2_, but we add a "_" for the one we are searching for
            var maindiv = jQuery('#pagebody').get(0);               
            jQuery.data(maindiv, "group", group); //write data to div
        }
        return invocation.proceed();
    }
);  


//http://sharepoint.stackexchange.com/questions/54186/how-to-use-aop-js-with-jquery-on-grouped-lists
jQuery.aop.after( {target: window, method: 'ExpGroupRenderData'}, 
    function(result) { 
        var maindiv = jQuery('#pagebody').get(0);
        var group = jQuery.data(maindiv, "group");
        if(group){
            setRatingsStyles();
            alert("found group" );
            jQuery.data(maindiv, "group", ""); //clear out data
        }
        return result;
    } 
);
</code></pre>

<p><strong>[update]</strong></p>

<p>...snip snip...</p>

<p>Using the code from <a href="http://www.sharepoint-howto.com/2011/12/20/sharepoint-aspect-oriented-programming-aop-with-jquery/#comment-14622" rel="nofollow">this page</a>, if I remove the <code>if (invocation.arguments[2] == 'true')</code> test, the function will, indeed, fire, but it only runs on a group that has already been expanded at least once.  (Now the styling works fine; I have a <a href="http://stackoverflow.com/questions/13898356/is-there-a-better-way-to-find-and-replace-a-class-based-on-its-contained-text/13898418#13898418">post on this here</a>).</p>

<p>_(just a note - you could use any div to store the jquery data property.  #pagebody is in my custom master page. I couldn't find a #MSO_ContentTable in my outputted code; but it stores the data just fine)_</p>

<p>The effect is that when the user expands a group, it does not get styled.  But if he expands a second group, the previous group gets styled, even if that group has been contracted.</p>

<p>If I leave the <code>if</code> clause, nothing ever happens. If I uncomment the <code>alert</code> in the <code>around</code> function, then I can see that the <code>invocation.arguments[2]</code> (which is the <code>isLoaded</code> property of the <code>ExpGroupRenderData</code> function) is always false when the <code>around</code> function checks it.  </p>

<p>It seems like the <code>aop.around</code> function does not wait long enough to check the value of <code>isLoaded</code>.</p>

<p>I have been stuck on this for days.  Can anyone make a suggestion?</p>

<p><strong>[update]</strong></p>

<p>This seems to work a <em>little</em> bit better.  At least it works now on the just-opened group if I open it, close it, and open it again.  That is one bit better, at least.</p>

<pre><code>jQuery.aop.after( {target: window, method: 'ExpCollGroup'}, //notice the method
    function() { 
        setRatingsStyles();
    } 
);
</code></pre>
