This question came from following up on an answer given here.
I want to use jQuery to work css modifications on a list that has grouping. I discovered a jQuery script called aop.js
that will allow you to attach function calls onto other functions. There is another page here with more explanation. And so, I came up with this, where I attach a function call onto ExpGroupRenderData
so that I can run a function AFTER the list items are grouped.
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();
}
);
//https://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;
}
);
[update]
...snip snip...
Using the code from this page, if I remove the if (invocation.arguments[2] == 'true')
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 post on this here).
_(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)_
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.
If I leave the if
clause, nothing ever happens. If I uncomment the alert
in the around
function, then I can see that the invocation.arguments[2]
(which is the isLoaded
property of the ExpGroupRenderData
function) is always false when the around
function checks it.
It seems like the aop.around
function does not wait long enough to check the value of isLoaded
.
I have been stuck on this for days. Can anyone make a suggestion?
[update]
This seems to work a little 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.
jQuery.aop.after( {target: window, method: 'ExpCollGroup'}, //notice the method
function() {
setRatingsStyles();
}
);