Forums

Forums / Developing Portals / Display N:N Relationship in a GridView

Display N:N Relationship in a GridView

Thread is closed for posting
5 posts, 2 answered
  1. julien.biedermann
    julien.biedermann avatar
    17 posts
    Registered:
    16 Jun 2016
    24 Jun 2016
    Link to this post
    Hello,

    I want to display a gridview on a page with all the accounts (until here no problem), then I want to have a row called "work area" to display a N:N Relationship (sub-grid in CRM).

    Example here : http://www.tiikoni.com/tis/view/?id=f23a1ab

    Is it possible to achieve that ?

    Thanks a lot,
    Julien 
    Last modified on 24 Jun 2016 07:06 by julien.biedermann
  2. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    Answered
    28 Jun 2016 in reply to julien.biedermann
    Link to this post
    Hello Julien,

    This is possible with the SavedQuery feature and some JavaScript code that executes on the column.

    I will provide some sample steps to do something similar to what you want, but with contacts under accounts instead of your custom relationship.

    Firstly you would have to create a SavedQuery that takes in the parameter of the row and returns a list of results:

    <fetch version="1.0" mapping="logical" output-format="xml-platform">
      <entity name="contact">
        <attribute name="contactid" />
        <attribute name="fullname" />
        <filter type="and">
          <condition attribute="parentcustomerid" operator="eq" value="@p1@" />
        </filter>
      </entity>
    </fetch>
    

    Secondly an additional "Literal" type column should be added to your grid to show the relationship results, make sure to add the code to the format HTML section:

    <script>GetRelationships({5})</script>
    



    Now, add a JavaScript widget to the page and put in the following script, changing the URL and output to your liking:

    function GetRelationships(info) {
      var accntId = info.primaryId;
      if(accntId) {
        var contacts = $.ajax("http://www.website.com/SavedQueryService/Execute/getcontactsforaccount/"+accntId,{
          async:true,
        }).done(function(data) {
          if(data&&data.length) {
          	var cell = $("#"+info.cell.id);
            var html = "";
            for(var i=0;i<data.length;i++) {
              html+=data[i].Attributes["fullname"];
              if(i != (data.length-1)){
                html+="<br/>";
              }
            }
            cell.append(html);
          }
        });
      }
    }
    

    Ensure the JavaScript widget is configured to include in the head tag.

    Finally your grid should look something like this:



    If you have any questions feel free to let me know.

    Regards,
    Clinton

    Last modified on 28 Jun 2016 14:06 by Clinton Bale
  3. quanganh
    quanganh avatar
    33 posts
    Registered:
    16 Jun 2016
    07 Jul 2016
    Link to this post
    Hello Clinton,

    Thanks for your answer. I follow your example and it's working. But I still have an issue.
    When we sort or move to another page (My grid view is paged) the custom column  (type literal) will be empty. How can we reload this column?

    Many thanks,
    Quang Anh
  4. quanganh
    quanganh avatar
    33 posts
    Registered:
    16 Jun 2016
    07 Jul 2016 in reply to quanganh
    Link to this post
    Another question:

    The custom column seems cannot sort or filter. Is it possible to use functions ?

    Many thanks,
    Quang Anh
  5. Clinton Bale
    Clinton Bale avatar
    126 posts
    Registered:
    21 Feb 2014
    Answered
    13 Jul 2016 in reply to quanganh
    Link to this post
    Hello Quang,

    This column and the script is executed on render. As long as you fire the Telerik RadGrid redender functions then the column should generate it's data again. Also ensure you have the JavaScript available on the page that you moved the grid to.

    For filtering, custom JavaScript filtering would have to be done as this is not a standard column. See the Telerik API on the RadGrid for more details.

    Regards,
    Clinton
5 posts, 2 answered