This is a migrated thread and some comments may be shown as answers.

Selectively expanding GridNestedView not working

1 Answer 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 02 Jun 2014, 05:50 PM
My example is using Entity Framework as it's data source. The requirement is that I have a Parent grid with high level details and a child grid with more details. In order to have the usability that I desire the user will click on a link in the child and navigate off of the page and it's position on the parent grid is retained. The desired behavior is that when the user returns to the page the previous Configuration should be retained. I have tried several examples that I have found in the forums but none of them seem to work. 

protected void rgCampaignGrid_ItemDataBound(object sender, GridItemEventArgs e)
{
    List<int> reviewedCampaigns = new List<int>();
    if (Session.Contents["ReviewedCampaigns"] != null)
    {
        reviewedCampaigns = (List<int>)Session.Contents["ReviewedCampaigns"];
    }

    if (e.Item is GridDataItem)
    {
        RadGrid parent = (RadGrid)sender;

        GridDataItem item = (GridDataItem)e.Item;
        int campaignId = Convert.ToInt32(item.GetDataKeyValue("CampaignId"));
        CampaignId = campaignId;


        if(reviewedCampaigns.Contains(campaignId))
        {
            e.Item.Expanded = true;
        }

        if (!reviewedCampaigns.Contains(CampaignId))
        {
            ((HyperLink)item["ApproveColumn"].FindControl("hkApprove")).Attributes.Add("onclick", "return CheckApprove('" + campaignId.ToString() + "');");
            ((HyperLink)item["ApproveColumn"].FindControl("hkApprove")).CssClass = string.Empty;
            ((HyperLink)item["DenyColumn"].FindControl("hkDeny")).Attributes.Add("onclick", "return CheckDeny('" + campaignId.ToString() + "');");
            ((HyperLink)item["DenyColumn"].FindControl("hkDeny")).CssClass = string.Empty;
        }
        else
        {
            ((HyperLink)item["ApproveColumn"].FindControl("hkApprove")).CssClass = "launchsubmit";
            ((HyperLink)item["ApproveColumn"].FindControl("hkApprove")).Attributes.Remove("onclick");
            ((HyperLink)item["DenyColumn"].FindControl("hkDeny")).CssClass = "launchsubmit";
            ((HyperLink)item["DenyColumn"].FindControl("hkDeny")).Attributes.Remove("onclick");
        }
    }
    if (e.Item is GridNestedViewItem)
    {
        GridNestedViewItem nestedView = (GridNestedViewItem)e.Item;
        if (reviewedCampaigns.Contains(CampaignId) && nestedView != null)
        {
            ((Panel)nestedView.FindControl("InnerContainer")).Visible = true;
        }
    }
}

protected void RgCampaignGrid_ItemCommand(object sender, GridCommandEventArgs e)
{
    UCampaign.ApprovalsClass cls = new ApprovalsClass(CurrentUserSession.ClientId, CurrentUserSession.CampaignUserProfile.CampaignUserId);
    RadGrid g = (RadGrid)sender;
    CampaignId = Convert.ToInt32(g.MasterTableView.DataKeyValues[e.Item.ItemIndex]["CampaignId"]);
    GridDataItem item = (GridDataItem)e.Item;
    GridNestedViewItem nestedView = (GridNestedViewItem)item.ChildItem;

    Panel pnl = (Panel)nestedView.FindControl("InnerContainer");

    pnl.Visible = !e.Item.Expanded;
    RadGrid eventRadGrid = (RadGrid)pnl.FindControl("rgEvents");
    cls.PopulateEventsGrid(ref eventRadGrid, CampaignId);

    List<int> reviewedCampaigns = new List<int>();
    if (Session.Contents["ReviewedCampaigns"] != null)
    {
        reviewedCampaigns = (List<int>)Session.Contents["ReviewedCampaigns"];
        if (!reviewedCampaigns.Contains(CampaignId))
        {
            reviewedCampaigns.Add(CampaignId);
            Session.Contents["ReviewedCampaigns"] = reviewedCampaigns;
        }
    }
    else
    {
        reviewedCampaigns.Add(CampaignId);
        Session.Add("ReviewedCampaigns", reviewedCampaigns);
    }
}

protected void RgCampaignGrid_PreRender(object sender, EventArgs e)
{
    List<int> reviewedCampaigns = new List<int>();
    if (Session.Contents["ReviewedCampaigns"] != null)
    {
        reviewedCampaigns = (List<int>)Session.Contents["ReviewedCampaigns"];
    }

    RadGrid radGrid1 = (RadGrid)sender;
    GridItem[] nestedViewItems = radGrid1.MasterTableView.GetItems(GridItemType.NestedView);
    foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
    {
        VwCampaignsReadyForApproval approval = (VwCampaignsReadyForApproval)nestedViewItem.DataItem;
        if (approval != null && reviewedCampaigns.Contains(Convert.ToInt32(approval.CampaignId)))
        {
            Panel pnl = (Panel)nestedViewItem.FindControl("InnerContainer");
            if (pnl != null)
            {
                pnl.Visible = true;
            }

        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 05 Jun 2014, 01:17 PM
Hello Robert,

If I understand your scenario correctly you would like to have the same items expanded in RadGrid after navigating back to the page.

The general approach for achieving this would be similar to the one you are using. When an item is expanded - keep its ID in a Session variable. Then, using the ItemDataBound event you could check that session variable and expand the item.

In case you would like to return the page to the same scroll position check out this article that suggests a possible approach for achieving such functionality.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or