Quantcast
Channel: Alan Ashton's Blog » Microsoft CRM
Viewing all articles
Browse latest Browse all 5

CRM 2011: Refresh Subgrids on Tab Expansion

$
0
0

Hi Folks

I just thought that I would share this snippet with anyone who may be interested. I have been looking at form design a lot recently with a view to cleaning the forms up. I have nearly everything in collapsed tabs and I think that this is the way to go for a cleaner form design. The user then sees the tab list and clicks on the tab that they are interested in.

The problem is that when the form is key (Say the Company form) that there may be a lot of tabs with subgrids. As we know already Microsoft CRM will only refresh the first four grids on the form automatically and the rest would require a further click.

I think that this might be mildly soul destroying for most users who click on a tab only to find out that there is a grid that needs a further click if its not in the first four.

What I wanted was a solution that opens all the grids in any tab that has been expanded.

I also wanted to ensure that this code could be run from anywhere in the application withough a ton of parameters.

The Solution
What I came up with was a piece of generic code that can be inserted as a simple web resource. This web resource can be added to any form as the code in it is completely generic and does not use any names of tabs or sections or controls.

Basically the idea is to do the following

1. Add the script as a global web resource
2. Attach the web resource to a form
3. For each tab that you wish to function in this manner attach to the ‘TabStateChange’ event and link to the function ‘GlobalOnChangeTabState’

*** IMPORTANT NOTE: Ensure that you pass the context when you hook up the event on the forms tab.

and you are done.

What I like about this is that its completely generic and can be simply added anywhere.

Have fun…..

Script Below

function GlobalPreLoadSubGrid(name)
{
var gridControl = Xrm.Page.ui.controls.get(name);
gridControl.refresh();

}

function GlobalOnChangeTabState(context)
{
var tab = context.getEventSource();
var currentTabState = tab.getDisplayState();

if(currentTabState == “expanded”)
{
//alert(“Tab: ” + tab.getName());

var tabSections = tab.sections.get();

for (var i in tabSections)
{
var section = tabSections[i];

var sectionName = section.getName();

//alert(“Section: ” + sectionName);

var sectionControls = section.controls.get();

for (var i in sectionControls)
{
var control = sectionControls[i];
var controlName = control.getName();

//alert(“Control: ” + control.getName() + ” Is a ” + control.getControlType());

if(control.getControlType() == “subgrid”)
{
GlobalPreLoadSubGrid(controlName);
}

}
}
}
}



Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images