Montag, 5. Oktober 2009

Prevent expanding grouping in listviews

Recently I got the requirement from a customer to deactivate the auto-expanding of groups in a single AllItems.aspx-Default-Listview that was grouped and should show at least 700 items per page.
First attempts where in vain to deactivate viewStates from the control or change webpart-attributes. A more promising approach seemed to be deleting browser-cookies. Reloading Firefox after deleting cookies worked like a charm but I've got no success to reproduce this behaviour by code.

So I had to try another way and began to debug the SharePoint-JavaScript by using Firebug. That was a good decision because I discovered this method:


In here a simple array is iterated over that's items are getting executed by eval-function.
One of the array-items is "ExpGroupOnPageLoad". This function cares for expanding each group if it's found in the state-cookie.

A little bit googling about the JS-Variable _spBodyOnLoadFunctionNames gave me a little bit more overview and so I tried to remove the
ExpGroupOnPageLoad-entry in hope that the groups stayed collapsed after reload. And voila! It worked like a charm!

Just add this piece of code in your AllItems.aspx (or another view-file) and the list-groupings stay closed after page-reload, no matter, what groups the user expanded before:

<script type="text/javascript">
for (var i = 0; i < _spBodyOnLoadFunctionNames.length; i++) {
if (_spBodyOnLoadFunctionNames[i] == "ExpGroupOnPageLoad") {
// remove only this one element from array

Lange nichts gehört... / Long time ago...

Seit meinem letzten Post ist einige Zeit vergangen, in der ich auch ein paar Tage im Urlaub war. Schöne Grüße nach Mallorca, wo während meines Aufenthalts die schlimmsten Unwetter der letzten 40 Jahre herrschten ;-)

Seit letzter Woche bin ich zurück und ausgeruht um neue neue SharePoint-Abenteuer zu bestehen. Ich hoffe, dass ich zukünftige Postings in kürzeren Abständen schreiben kann. Diese werden dann, beginnend ab dem nächsten, komplett in Englisch sein. Ebenfalls habe ich vor, das etwas angestaubte Design des Blogs ein wenig zu überarbeiten.

Damit der Übergang zum Sprachwechsel nicht ganz so hart ausfällt, hier die englische Version:

English version:

Since my last post some time elapsed, which I used for making holidays and other lovely things.
Greetings to Mallorca, Spain that suffered from the heaviest thunderstorm since the last 40 years. ;-)

Now I'm back since last week and feel refreshed to look forward new SharePoint-Adventures. I hope to shorten the delays between my upcoming blogposts which I'll try to write henceforth completely in english. I also want to redesign the blog-layout a little bit.

So that the change-over for my readers isn't that hard, this posting is a mixture from german and english.