How to filter a subgrid RRS feed

  • Question

  • Here it's a great post for but dont know why it dont work.



    Here is my requirement:

    The subgrid should be filtered according to the Xrm.Page.data.entity. That is I need set filter for the subgrid only once. So I decide to set the filter before the subgrid load data.

    I customizied a view as the default view for my subgrid, And then I put the subgrid to a tab which is collapsed by default, and when the tab is expanded for the first time, I get some attributes of the entity from current form, then build and set the filter for the subgrid.

    Now subgrid send a request to server to fetch data.


    The problem is when I call getParameter, i get nothing, 

     I captured divGridParams in my html document, there are some childNodes, but there is only 1 xml-formated node -- layoutXml.  

     All fetchXml,effectiveFetchXml,fetchXmlForFilters are missing.

     After I call setParameter(field,b),  fetchXml,effectiveFetchXml,fetchXmlForFilters, are manually inserted at childNodes into divGridParams.

     But when refresh the subgrid. I got some javascript error


    an js error occur here:

    ->this.$A_3.SetParameter(“fetchXml”,this.get_transientFetch())  (in GridFilter.js)
    ->get_transientFetch:function(){return this.$1L_3.xml} (in global.ashx)

    $L_3 is null.


    var related_case_first_time = true;
     function relatedCasesTab_onExpanded() {
     var relatedCasesTab = Xrm.Page.ui.tabs.get(4);
     if (relatedCasesTab.getDisplayState() == 'expanded' && related_case_first_time) {
     var gridName = 'Related_Cases';
     var fetchXml = '';
    document.getElementById(gridName + '_filterSet').control.RefreshWithFilters();
    var attrs = Xrm.Page.data.entity.attributes;
     var ticketnumber = attrs.get('ticketnumber').getValue();
     var macaddress = attrs.get('new_macaddress').getValue();
     var ipaddress = attrs.get('new_ipaddress').getValue();
     var machinename = attrs.get('new_machinename').getValue();
    var updateXml = function (grid, field) {
     try {
     //var g = Xrm.Page.getControl(grid)._control.get_innerControl();
     var g = document.getElementById(grid).control;
     var b = updateFetchXml(fetchXml, field);
     g.setParameter(field, b);
     } catch (e) { }
    var updateFetchXml = function (fetchxml, field) {
     var flag = 0;
     var ptn = /<filter[\w\s='"\.\/]*/;
    if (macaddress == null || macaddress == '') ++flag;
     if (ipaddress == null || ipaddress == '') ++flag;
     if (machinename == null || machinename == '') ++flag;
    if (flag == 3) { return fetchXml.replace(ptn, '') };
    var filterArr = new Array();
    if (flag > 1) filterArr.push('');
     if (macaddress != null && macaddress != '') filterArr.push('');
     if (ipaddress != null && ipaddress != '') filterArr.push('');
     if (machinename != null && machinename != '') filterArr.push('');
     if (flag > 1) filterArr.push('');
    fetchxml = fetchxml.replace(ptn, filterArr.join(''));
     return fetchXml;
    // Update the fetchXml
     updateXml(gridName, "fetchXml");
    // It does not use either of these for filtering, but...
     // I'm not sure where else these could be referenced
     updateXml(gridName, "effectiveFetchXml");
     updateXml(gridName, "fetchXmlForFilters");
    // Refresh the grid
     related_case_first_time = false;


    Any solution about that?
    Thanks in advance.

    Friday, April 29, 2011 8:56 AM


  • Finally, I use Iframe for a replacement.
    • Marked as answer by shu nan Friday, May 6, 2011 3:22 AM
    Friday, May 6, 2011 3:22 AM

All replies

  • Finally, I use Iframe for a replacement.
    • Marked as answer by shu nan Friday, May 6, 2011 3:22 AM
    Friday, May 6, 2011 3:22 AM
  • hi, how did you do with iframe?


    Tuesday, August 9, 2011 6:26 AM
  • Hi Shun,


         can you plz explain how to do this using IFrame. I am also having same requirement. In Iframe how we can apply filter to subgrid.



    Guru Prasad
    Friday, December 16, 2011 6:05 AM