I have a little question, there is a listview webpart that is grouped on a specific column, called status, the status has 2 values, Opened, Closed, In Progress. There is a plus, minus buttons beside the group name, I want to make the whole row clickable when clicking the row, not just the +,- signs. How do I achieve that?

There are articles that use the javascript function: expcollgroup but I don't know how to use it in this case, how to give this function to the whole row?


Pressing F12 on the view should give you the developer view in IE. From here if you select the little plus sign then you can see that there is an ONCLICK event assigned to the A tag relating to the ExpCollGroup function.

<a onclick="javascript:ExpCollGroup('6-1_', 'img_6-1_',event, false);return false;" href="javascript:">

So what you need to do is apply that function to the containing TR (or TD) tag instead.

<td class="ms-gb" noWrap="" colSpan="100" onclick="javascript:ExpCollGroup('6-1_', 'img_6-1_',event, false);return false;">

EDIT: example of script to apply ONCLICK to TD

var myTd = $("table.ms-listviewtable td.ms-gb");
$.each(myTd, function() {
 var strOnClick = $(this).children("a").attr("onclick");

This could be simplified but I have tried to make it obvious what steps I am taking. As mentioned below, you may need to refine this to make sure it is selecting the correct items but essentially this should be OK.

  • Hi Dave, Thanks for your reply, but the value 6_1 and img_6_1 is going to be changed, it's variable not static, what if the user adds more groups? I want to apply the function as generic to the whole row. Jun 16 '13 at 4:39
  • I know I can use JQuery to append the ExpCollGroup function with "this" keyword, but I don't know how to do that. Jun 16 '13 at 4:40
  • Easiest approach will probably be to take the value of the ONCLICK as it is and add it to the TD - I will amend my response above with an example of the script but you may need to refine it. Jun 16 '13 at 7:26
  • I thanks for your response, I am getting there :) But I wrote this code: var myTd = $("table.ms-listviewtable td.ms-gb"); var strOnClick = myTd.children("a").attr("onclick"); myTd.attr("onclick",strOnClick); Seems like when I click on any td, it expands the first td, how do I attach the function to all tds. Thanks Dave for your help Jun 16 '13 at 12:42
  • Ah - my fault, need to loop through each of the TDs. Jun 16 '13 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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