Domanda

I'm trying to get the functionality of being able to click anywhere in the group by header element to expand and collapse the group. I have gotten close where I can click anywhere in the element except the actual anchor tag and it will work. With the script I'm using it is clicking the anchor on click within the parent element. I'm not sure how to get the conditional to work if the user actually clicks the anchor. Any suggestions?

$(document).ready(function() { 
var groupby = $(".ms-gb");
    groupby.click(function(){
        var groupbyAnchor = $("a", this);
        groupbyAnchor = groupbyAnchor[0];
        expandThisGroup(groupbyAnchor)}); 
});

function expandThisGroup(anchor) {
    anchor.click(); 
}
È stato utile?

Soluzione

With a little help from the guys over at stackoverflow I got this figured out. Putting a handler on the <a> tag that stops event propagation.

What I added:

groupby.find("a").click(function(e) {
    e.stopPropagation();
});

What it all looks like:

$(document).ready(function() { 
    var groupby = $(".ms-gb");
    groupby.click(function(){
        var groupbyAnchor = $("a", this);
        groupbyAnchor = groupbyAnchor[0];
        expandThisGroup(groupbyAnchor)}); 
    groupby.find("a").click(function(e) {
        e.stopPropagation();
    });
});

function expandThisGroup(anchor) {
    anchor.click(); 
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top