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

Hide column in Detail Tables of RadGrid

4 Answers 1270 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Tom
Top achievements
Rank 1
Tom asked on 07 Jan 2011, 09:09 PM
Hello,

I have a RadGrid in which I may need to hide a column in the detail tables of a Hierarchical table depending on the configuration of the user logged into the system.  I cannot determine how to do this since I am already doing some customization for a vertical scrollbar in the detail tables.  I am attempting to hide the UnitOfMeasure column.

Below are the designer and code-behind snippets for the table.

Designer:
<div>
<telerik:RadGrid ID="RadGridOrderStatus" runat="server" AutoGenerateColumns="false" PageSize="10" AllowSorting="True" AllowPaging="true" Skin="Simple" 
        CssClass="RegistrationFieldStyle" HeaderStyle-CssClass="RegistrationFieldStyle" Width="90%" HorizontalAlign="Left" ItemStyle-Wrap="false"
        OnItemCreated="RadGridOrderStatus_ItemCreated" OnPreRender="RadGridOrderStatus_PreRender"
        OnNeedDataSource="RadGridOrderStatus_NeedDataSource" OnItemDataBound="RadGridOrderStatus_ItemDataBound" OnDetailTableDataBind="RadGridOrderStatus_DetailTableDataBind">
    <PagerStyle Mode="NumericPages" />
    <ClientSettings>
        <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    </ClientSettings>
    <MasterTableView TableLayout="Fixed" AllowMultiColumnSorting="true" DataKeyNames="OrderNumber" Name="ORDER" ShowFooter="false" HierarchyLoadMode="Client"
        PagerStyle-AlwaysVisible="true" HorizontalAlign="Left" >
        <DetailTables>
            <telerik:GridTableView DataKeyNames="OrderNumber" runat="server" Width="100%" Name="ORDERDETAIL">
                <ParentTableRelation>
                    <telerik:GridRelationFields DetailKeyField="OrderNumber" MasterKeyField="OrderNumber" />
                </ParentTableRelation>
                <NoRecordsTemplate>
                    <asp:Label ID="lblMsg" runat="server" Text="No Order Detail Records Found"></asp:Label>
                </NoRecordsTemplate>
                <Columns>
                    <telerik:GridBoundColumn HeaderText="NDC" HeaderButtonType="TextButton" DataField="NDCNumber" />
                    <telerik:GridBoundColumn HeaderText="Description" HeaderButtonType="TextButton" DataField="Description" />
                    <telerik:GridBoundColumn HeaderText="Unit Of Measure" HeaderButtonType="TextButton" DataField="UnitOfMeasure" />
                    <telerik:GridBoundColumn HeaderText="Requested Quantity" HeaderButtonType="TextButton" DataField="RequestedQty" />
                    <telerik:GridBoundColumn HeaderText="Shipped Quantity" HeaderButtonType="TextButton" DataField="ShippedQty" />
                    <telerik:GridBoundColumn HeaderText="Ship Date" HeaderButtonType="TextButton" DataField="ShipDate" DataFormatString="{0:MM/dd/yyyy hh:mm tt}" />
                    <telerik:GridHyperLinkColumn HeaderText="Tracking Number" HeaderButtonType="TextButton" DataTextField="Shipment.WaybillNumber" DataTextFormatString="{0}" 
                        DataNavigateUrlFields="Shipment.WaybillNumberCarrierUrl" DataNavigateUrlFormatString="{0}" Target="_blank" />
                    <telerik:GridBoundColumn HeaderText="Status" HeaderButtonType="TextButton" DataField="Shipment.Status" />
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridBoundColumn HeaderText="Order Date" HeaderButtonType="TextButton" DataField="OrderDate" DataFormatString="{0:MM/dd/yyyy hh:mm tt}" HeaderStyle-Width="120px" ItemStyle-HorizontalAlign="Left" />
            <telerik:GridBoundColumn HeaderText="Transaction Number" HeaderButtonType="TextButton" DataField="OrderNumber" HeaderStyle-Width="80px" ItemStyle-HorizontalAlign="Left" />
            <telerik:GridTemplateColumn HeaderText="Ordered By" HeaderButtonType="TextButton" HeaderStyle-Width="100px" ItemStyle-HorizontalAlign="Left">
                <ItemTemplate>
                    <asp:Label ID="ContactName" runat="server" />
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn HeaderText="Address" HeaderButtonType="TextButton" DataField="ShipToAddress.FullBlockAddress" HeaderStyle-Width="200px" ItemStyle-HorizontalAlign="Left" />
            <telerik:GridBoundColumn HeaderText="Status" HeaderButtonType="TextButton" DataField="OrderStatus" HeaderStyle-Width="100px" ItemStyle-HorizontalAlign="Left" />
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
</div>

Code-Behind:
#region RadGridOrderStatus_DetailTableDataBind
protected void RadGridOrderStatus_DetailTableDataBind(object sender, GridDetailTableDataBindEventArgs e)
{
        GridDataItem orderItem = e.DetailTableView.ParentItem;
        if (e.DetailTableView.Name.ToUpper() == "ORDERDETAIL" && 
            orderItem.DataItem is Order)
        {
            Order parentOrder = (Order)orderItem.DataItem;
            e.DetailTableView.DataSource = parentOrder.Products;
        }
}
#endregion
#region RadGridOrderStatus_ItemCreated
protected void RadGridOrderStatus_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridNestedViewItem)
    {
        GridNestedViewItem nestedItem = e.Item as GridNestedViewItem;
        nestedItem.NestedViewCell.PreRender +=new EventHandler(NestedViewCell_PreRender);
    }
}
protected void NestedViewCell_PreRender(object sender, EventArgs e)
{
    ((Control)sender).Controls[0].SetRenderMethodDelegate(new RenderMethod(this.NestedViewTable_Render));
}
protected void NestedViewTable_Render(HtmlTextWriter writer, Control control)
{
    control.SetRenderMethodDelegate(null);
    writer.Write("<div style='height: 100%; overflow: scroll;'>");
    control.RenderControl(writer);
    writer.Write("</div>");
}
#endregion
#region RadGridOrderStatus_ItemDataBound
protected void RadGridOrderStatus_ItemDataBound(object sender, GridItemEventArgs e)
{
        if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            if (e.Item.DataItem is Order)
            {
                Order parentOrder = (Order)e.Item.DataItem;
                Label contactName = (Label)e.Item.FindControl("ContactName");
                switch (LocalSettings.CurrentUserProfile.RegistrationType.RegistrationTypeCode)
                {
                    case EnumRegistrationType.HCP:
                    case EnumRegistrationType.PHARMACIST:
                        contactName.Text = parentOrder.ContactFirstName + " " +
                            parentOrder.ContactLastName;
                        break;
                }
            }
        }
}
#endregion
#region RadGridOrderStatus_NeedDataSource
protected void RadGridOrderStatus_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
         RadGridOrderStatus.DataSource = LocalSettings.CurrentOrderSearchResponse.Orders;
}
#endregion



Your assistance is greatly appreciated.

Thanks

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Jan 2011, 05:32 AM
Hello Tom,

Try the following code in PreRender event to hide the column in DetailTable.

C#:
protected void RadGridOrderStatus_PreRender(object sender, EventArgs e)
 {
   RadGridOrderStatus.MasterTableView.DetailTables[0].GetColumn("UnitOfMeasure").Visible = false;
 }

Thanks,
Princy.
0
Tom
Top achievements
Rank 1
answered on 11 Jan 2011, 12:17 PM
Hi Princy,

I made the modifications that you indicated (i.e. added OnPreRender="RadGridOrderStatus_PreRender" event to the grid and added UniqueName="UnitOfMeasure" to the column in the detail table that I wish to hide).

On the code-behind side, I added the code below.

protected void RadGridOrderStatus_PreRender(object sender, EventArgs e)
 {
         CampaignConfig hideUOM = CampaignConfig.GetCampaignConfig(LocalSettings.CurrentCampaign.CampaignId, EnumCampaignConfiguration.HIDE_UOM.ToString());
         if (hideUOM.ActiveFlag)
         {
             RadGridOrderStatus.MasterTableView.DetailTables[0].GetColumn("UnitOfMeasure").Visible = false;
         }
}

The Unit Of Measure column is not being hidden in any of the detail tables however.  Do you have any ideas on why it is not being hidden?  Would the DetailTableBind event or NestedViewCell code interfere?

Thanks,

0
Accepted
Pavlina
Telerik team
answered on 14 Jan 2011, 09:31 AM
Hi Tom,

You could try hiding the columns using the approach suggested by my colleague at that address. Please, note what he explains in the post:

The GridTableView.DetailTables collection is only a set of templates for creating the nested tables. The real detail tables are contained in the GridDataItem.ChildItem.NestedTableViews collection.

Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Tom
Top achievements
Rank 1
answered on 15 Jan 2011, 01:36 PM
Hi Pavlina,

Using your suggestion, I made the code changes to the MasterTableView prerender event and was successful in implementing.

protected void RadGridOrderStatus_PreRender(object sender, EventArgs e)
{
        CampaignConfig hideUOM = CampaignConfig.GetCampaignConfig(LocalSettings.CurrentCampaign.CampaignId, EnumCampaignConfiguration.HIDE_UOM.ToString());
        if (hideUOM.ActiveFlag)
        {
            // determine if there are detail tables of the master view
            if (RadGridOrderStatus.MasterTableView.HasDetailTables)
            {
                // for each master record, check if there are child items and if so loop through and hide the column
                foreach (GridDataItem item in RadGridOrderStatus.MasterTableView.Items)
                {
                    if (item.HasChildItems)
                    {
                        foreach (GridTableView innerDetailView in item.ChildItem.NestedTableViews)
                        {
                            GridColumn unitOfMeasure = innerDetailView.GetColumn("UnitOfMeasure");
                            unitOfMeasure.Visible = false;
                        }
                    }
                }
            }
        }
}


Thanks
Tags
Grid
Asked by
Tom
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Tom
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or