Home > SharePoint 2010 > Fix the Ajax JavaScript issues with group by for ListView and ListViewByQuery

Fix the Ajax JavaScript issues with group by for ListView and ListViewByQuery

If you are using ListView or ListViewByQuery to display SharePoint list data with group by in the view, you might find yourself with some Ajax JavaScript issues with group by.

When you expand any group in your list view it’s just saying “Loading…” and not loading any data as shown below.

Problem:


Solution:

To fix the issues, you need to do some JavaScript hacks.

First set the Collapse attribute to FALSE (or by default, show groupings: Expanded) and place your ListViewByQuery control in a DIV and give this DIV an ID. Immediately after the DIV add the following JavaScript(the JavaScript click the node and collapse the node) : 

<div id=”ViewDiv” class=”ms-authoringcontrols” style=”width:700px”>

     <spuc:ListViewByQuery ID=”CustomersListViewByQuery” runat=”server” Width=”700px” />

</div>

<script language=”javascript”>

    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 i = 0; i < links.length; i++) {

               if (links[i].href == “javascript:” && links[i].onclick.toString().indexOf(“ExpCollGroup”) > -1) {

                   //alert(links[i]);

                   links[i].click();

                }

            }

        }

    }

    var expLnk = new ExpLinkFormer(‘ViewDiv’);

</script>

Happy SharePointing

Source Code

You can download a source code here.

Advertisements
Categories: SharePoint 2010
  1. win
    May 1, 2013 at 8:32 pm

    Hello,

    Is this work for listview?

    thanks in advance,
    win

  1. No trackbacks yet.

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: