martedì, dicembre 01, 2009

SharePoint: Using JavaScript to Open Only the First Group in a Collapsed View

It seems to be pretty easy to create a grouped list with all items collapsed except for the first group. How? By taking advantage of a function called “ExpCollGroup” SharePoint already includes on the page. The only item you need to determine is the ID of the element you would like to expand.

You can add the following code snippet in a Content Editor Web Part. Make sure to add it below the actual list (the list needs to render in HTML before it can be altered.) Note that the ID of 2-1 (in italics) will vary and need to be looked up per instance.

<script type="text/javascript">

// Expand the first item in the grouped list

ExpCollGroup('2-1_','img_2-1_');

</script>