Always keep the Filter section expanded in AxGridView
During AxUG Webinar, I got a question around how to keep the filter section always expanded in a gridview in Microsoft Dynamics AX 2009 EP. Unfortunately we don't have a simple property to do that in the AxGridView control. Since it's all ASP.NET and javascript, I mentioned that there should be an easy workaround available.
If you add the below javascript code to your user control at the bottom of the markup file ( .ascx file) then the filter section will always be in expanded mode both during initial load as well as during subsequent postbacks. Since the below code uses lot's of internals such as ids and stylesheet names, it is not guaranteed to work in subsequent releases of EP. But if you need this capability in Ax 2009 and specific pages, this may be useful.
<script type="text/javascript">
function ExpandFilter(sender, args) {
var elem = document.getElementById('div_<%=this.AxGridView1.FilterControl.ClientID%>');
var parentDiv = elem.parentNode;
var filterArea = DynamicsFilter.GetFilterArea(elem);
if (DynamicsCommon.IsNull(filterArea)) return;
elem.style.display = '';
var applylink = DynamicsCommon.FindInstance(parentDiv, "applyfilter");
var resetlink = DynamicsCommon.FindInstance(parentDiv, "resetfilter");
var editfilterlink = DynamicsCommon.FindInstance(parentDiv, "editfilter");
if (!DynamicsCommon.IsNull(applylink) && !DynamicsCommon.IsNull(resetlink) && !DynamicsCommon.IsNull(editfilterlink)) {
editfilterlink.style.display = 'none';
applylink.style.display = '';
resetlink.style.display = '';
}
}
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(ExpandFilter);
ExpandFilter();
</
script>
Comments
Anonymous
September 14, 2009
void Page_Load(object sender, EventArgs e) { grid.FilterControl.PreRender += new EventHandler(FilterControl_PreRender); } void FilterControl_PreRender(object sender, EventArgs e) { if (!this.IsPostBack) { HiddenField axFilterShown = (HiddenField)((AxFilter)sender).FindControl("AxFilterShown"); axFilterShown.Value = "1"; } }Anonymous
September 14, 2009
Forgot the comment, but this is just another way to do, but then using code behind.Anonymous
January 17, 2011
Meysun, John, many thanks for this topic. Is there the way also to open the filter with "Add filter" link which is "pushed" already? I mean to see "Select Field" & "Is" when page opens.Anonymous
February 02, 2011
Meysun & John Hermsen , you guys are cool. It works brilliently in AX Grid view, but i want to achieve it in the AX Lookup the same functionality as my client wants it visible with all filter fields shown to the users as they used to do it in AX4.0 using webForms. I know it could be achieved using PopupControl but i would like to do it with AXLookup as it more easy and faster the creating user controls for popupchildcontrols blablabla. your help in this regard will be very much appritiated.Anonymous
February 02, 2011
Hi Meysun, I wanted to let the user filter the projects based on the dimensions, Even though I have added the first 4 dimension fields(we are using 8) . Dimensions are shown in the grid they are not appearing to be filtered on. I have checked at other places where the these are used in EP, not at a single place you can filter on them. I have created a new user control using AX Grid and have tested it. Can you please help in here. and one more thing, is it possible to keep the AXLookup Filter section auto expanded and let the dimesion filter shown automatically for the user so that user can just select the dimensions required and hit enter to filter the projects. as there are thousands of projects narrowing them down is very essential. Thanks in Advance. Maqsood