Karine Bosch’s Blog

On SharePoint

The ListViewByQuery Control


Lately I’ve been busy documenting the out of the box SharePoint controls. There are out of the box user controls, which are located in the 12\TEMPLATE\CONTROLTEMPLATES folder. There are a lot of server controls ready to be used by you and are located in the Microsoft.SharePoint.WebControls namespace of the Microsoft.SharePoint.dll.

One of the controls I describe is the ListViewByQuery control. One of my blog readers pointed me to a problem with this controls when using a GroupBy query.

string query = "<GroupBy Collapse='FALSE'><FieldRef Name='CountryRegionName' /><FieldRef Name='City' /></GroupBy>";
SPQuery qry = new SPQuery(list.DefaultView);
qry.Query = query;
qry.RowLimit = 2000;
CustomersListViewByQuery.Query = qry;

When you specify that you want to show the groups collapsed, you can expand all groups, except the most inner one. It show a Loading label but nothing ever happens:

listviewbyquery-collapsed-expanding

I tried to solve this problem by using a javascript added to the content control. This javascript function retrieved all <a> elements and executed the onclick method defined on it. This resulted in too much click events that didn’t need to execute, so I tried to get to the <a> elements that execute the expand/collapse function. The following code snippet shows the code that is generated by SharePoint when the page is rendered. You can see that the <a> element doesn’t have an ID nor name which makes it rather impossible to get a grip on only the hyperlinks for expanding and collapsing the groups.

<a href="javascript:" onclick="javascript:ExpCollGroup('1-1_','img_1-1_');return false;">CountryRegionName</a> :&nbsp;Australia

If someone else achieves this, I will be glad to here it!

Advertisements

April 7, 2009 - Posted by | SharePoint 2007

6 Comments »

  1. Hi Karine.
    >get a grip on only the hyperlinks for expanding and collapsing the groups

    ExpLinkFormer = function(divId) {
    this._DivId = divId;
    this._init();
    }

    ExpLinkFormer.prototype = {
    _init: function() {
    var div = document.getElementById(this._DivId);
    var links = div.getElementsByTagName("a");

    Comment by Alex | April 14, 2009 | Reply

  2. can’t add my post…

    Comment by Alex | April 14, 2009 | Reply


  3. ExpLinkFormer = function(divId) {
    this._DivId = divId;
    this._init();
    }

    ExpLinkFormer.prototype = {
    _init: function() {
    var div = document.getElementById(this._DivId);
    var links = div.getElementsByTagName("a");

    for (var ii = 0; ii -1) {
    alert(links[ii]);
    }
    }
    }
    }

    var expLnk = new ExpLinkFormer('DivId');

    Comment by Alex | April 14, 2009 | Reply

  4. >get a grip on only the hyperlinks for expanding and collapsing the groups

    Here is example how to get hyperlinks for expanding and collapsing the groups

    What we have to do later?

    Comment by Alex | April 14, 2009 | Reply

    • Hi Alex,

      Sorry that it took me so long to test your solution out. I was busy writing a white paper and wanted to have that finished first.

      Your piece of javascript works. I only added the

      links[i].click();

      in your loop.

      I added the code and the necessary explanation to my page that explains the use ListViewByQuery control.

      Thank you very much for your help!

      Comment by Karine | May 20, 2009 | Reply

  5. HI, I did not understand where to add this javascript. I have implemented a webpart. TO include this javascripty do i need to add usercontrol and in source file i need to add this javascript.
    Help on grouping is urgently needed. thnks!

    Comment by shweta | August 25, 2011 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: