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

Hide Group By Column

4 Answers 405 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 04 Nov 2008, 07:21 AM
Is there a way to toggle the display of a column depending on if it is being used as a group by expression?

Here's the scenario: As users create complex grouping sets, I want to remove the column they are grouping on from the list of columns. For example, they decide to group on category. Instead of showing category in the list of columns, now I don't need it since the items are grouped by category. They decide to remove the grouping for category, so it needs to be placed back into the grid.

Is this possible with a short amount of code?

Here's the code I'm currently using:

 

<telerik:RadGrid ID="CurrentCostCentersGrid" runat="server" Skin="Office2007" AllowMultiRowSelection="True"

 

 

AllowMultiRowEdit="True" ShowGroupPanel="True" AllowPaging="True" DataSourceID="DataSourceUnits"

 

 

GridLines="None" AutoGenerateColumns="False" PageSize="50" ShowFooter="true">

 

 

<ClientSettings AllowDragToGroup="true" AllowGroupExpandCollapse="true" AllowColumnsReorder="true"

 

 

AllowExpandCollapse="true">

 

 

<Selecting AllowRowSelect="true" />

 

 

<ClientEvents OnRowSelected="CostCenterSelected" OnRowDeselected="CostCenterUnselected" />

 

 

</ClientSettings>

 

 

<GroupPanel Enabled="true" Text="Groups">

 

 

</GroupPanel>

 

 

<PagerStyle Mode="NextPrevAndNumeric" NextPageText="Next" PrevPageText="Previous" />

 

 

<MasterTableView ShowGroupFooter="true" ShowFooter="true" DataSourceID="DataSourceUnits"

 

 

DataKeyNames="CostCenterItemID" CommandItemDisplay="None" ClientDataKeyNames="CostCenterItemID">

 

 

<CommandItemTemplate>

 

 

<asp:Button ID="BulkApproveButton" runat="server" Text="Bulk Approve" />

 

 

</CommandItemTemplate>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn Visible="False">

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridClientSelectColumn>

 

 

</telerik:GridClientSelectColumn>

 

 

<telerik:GridBoundColumn HeaderText="Fund" DataField="FundID" AllowFiltering="true"

 

 

DataType="System.Int32" SortExpression="FundID" ReadOnly="True" UniqueName="Fund" />

 

 

<telerik:GridBoundColumn HeaderText="Unit" DataField="UnitID" AllowFiltering="true"

 

 

DataType="System.Int32" SortExpression="UnitID" ReadOnly="True" UniqueName="Unit" />

 

 

<telerik:GridBoundColumn HeaderText="Line Item" DataField="LineItemID" AllowFiltering="true"

 

 

DataType="System.Int32" SortExpression="LineItemID" ReadOnly="True" UniqueName="LineItem" />

 

 

<telerik:GridBoundColumn HeaderText="Description" DataField="LineItemName" SortExpression="LineItemName"

 

 

UniqueName="Description" ReadOnly="true" Groupable="false" />

 

 

<telerik:GridBoundColumn HeaderText="Previous Budget" DataField="PreviousBudget"

 

 

AllowFiltering="true" DataType="System.Decimal" SortExpression="PreviousBudget"

 

 

UniqueName="PreviousBudget" DataFormatString="{0:C}" ReadOnly="True" Aggregate="Sum"

 

 

FooterAggregateFormatString="{0:C}" Groupable="false" />

 

 

<telerik:GridBoundColumn HeaderText="Previous Actual" DataField="PreviousActual"

 

 

DataType="System.Decimal" SortExpression="PreviousActual" UniqueName="PreviousActual"

 

 

DataFormatString="{0:C}" Groupable="false" Aggregate="Sum" FooterAggregateFormatString="{0:C}" />

 

 

<telerik:GridBoundColumn HeaderText="Current Budget" DataField="CurrentBudget" DataType="System.Decimal"

 

 

SortExpression="CurrentBudget" UniqueName="CurrentBudget" DataFormatString="{0:C}"

 

 

Groupable="false" Aggregate="Sum" FooterAggregateFormatString="{0:C}" />

 

 

<telerik:GridBoundColumn HeaderText="Current YTD" DataField="CurrentYTD" DataType="System.Decimal"

 

 

SortExpression="CurrentYTD" UniqueName="CurrentYTD" DataFormatString="{0:C}"

 

 

Groupable="false" Aggregate="Sum" FooterAggregateFormatString="{0:C}" />

 

 

<telerik:GridBoundColumn HeaderText="Proposed Budget" DataField="ProposedBudget"

 

 

DataType="System.Decimal" SortExpression="ProposedBudget" UniqueName="ProposedBudget"

 

 

Groupable="false" Aggregate="Sum" FooterAggregateFormatString="{0:C}" DataFormatString="{0:C}" />

 

 

<telerik:GridBoundColumn DataField="Category" EmptyDataText="&amp;nbsp;" HeaderText="Category"

 

 

SortExpression="Category" UniqueName="Category">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="StatusName" EmptyDataText="&amp;nbsp;" HeaderText="Status"

 

 

SortExpression="StatusName" UniqueName="StatusName">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn HeaderText="Modify Date" DataField="ModifyDate" DataType="System.DateTime"

 

 

SortExpression="ModifyDate" UniqueName="ModifyDate" />

 

 

</Columns>

 

 

<DetailTables>

 

 

<telerik:GridTableView DataSourceID="DataSourceHistory" AutoGenerateColumns="false"

 

 

ShowHeader="false" GroupsDefaultExpanded="false" NoDetailRecordsText="No notes currently exist for this item"

 

 

Width="85%" CommandItemDisplay="Top">

 

 

<CommandItemTemplate>

 

 

<telerik:RadToolBar ID="DetailsToolbar" runat="server" Skin="WebBlue" Width="100%"

 

 

AutoPostBack="true">

 

 

<ExpandAnimation Type="OutQuad" Duration="150" />

 

 

<CollapseAnimation Type="InQuad" Duration="150" />

 

 

<Items>

 

 

<telerik:RadToolBarButton Text="Make Request" CommandName="MakeRequest" ImageUrl="Images/request.gif">

 

 

</telerik:RadToolBarButton>

 

 

<telerik:RadToolBarButton IsSeparator="true">

 

 

</telerik:RadToolBarButton>

 

 

<telerik:RadToolBarDropDown Text="Approvals">

 

 

<Buttons>

 

 

<telerik:RadToolBarButton Text="Approved" CommandName="ManagerApprove" ImageUrl="Images/approve.gif">

 

 

</telerik:RadToolBarButton>

 

 

<telerik:RadToolBarButton Text="Rejected" CommandName="ManagerReject" ImageUrl="Images/reject.gif">

 

 

</telerik:RadToolBarButton>

 

 

<telerik:RadToolBarButton Text="Approve - Lock" CommandName="PortalApprove" ImageUrl="Images/paapprove.gif">

 

 

</telerik:RadToolBarButton>

 

 

<telerik:RadToolBarButton Text="Reject - Back to Manager" CommandArgument="PortalReject"

 

 

ImageUrl="Images/pareject.gif">

 

 

</telerik:RadToolBarButton>

 

 

</Buttons>

 

 

</telerik:RadToolBarDropDown>

 

 

</Items>

 

 

</telerik:RadToolBar>

 

 

</CommandItemTemplate>

 

 

<ParentTableRelation>

 

 

<telerik:GridRelationFields MasterKeyField="CostCenterItemID" DetailKeyField="ItemID" />

 

 

</ParentTableRelation>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px"></HeaderStyle>

 

 

</ExpandCollapseColumn>

 

 

<Columns>

 

 

<telerik:GridTemplateColumn>

 

 

<ItemTemplate>

 

 

<strong>

 

<%

#Eval("CreateDate","{0:d}") %>&nbsp;<%#Eval("CreateDate","{0:t}") %>&nbsp;-&nbsp;<%#Eval("UserName")%>:</strong>&nbsp;

 

<%

#Eval("NoteText")%><br />

 

 

<strong style="color: Red">Requested Increase:</strong>&nbsp;

 

<%

#Eval("RequestedBudget", "{0:C}")%>

 

 

</ItemTemplate>

 

 

</telerik:GridTemplateColumn>

 

 

</Columns>

 

 

</telerik:GridTableView>

 

 

</DetailTables>

 

 

<PagerStyle Mode="NextPrevAndNumeric" />

 

 

<PagerTemplate>

 

Item Description

 

</PagerTemplate>

 

 

</MasterTableView>

 

 

<FilterMenu EnableTheming="True" Skin="Gray">

 

 

<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>

 

 

</FilterMenu>

 

 

</telerik:RadGrid>

 

4 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Nov 2008, 07:34 AM
Hello Chris,

Check out the following code library which explains how to hide the grouped column in RadGrid and then show it again when ungroup action is progressed.
Show/hide grouped columns on group/ungroup action

Thanks
Princy.
0
Chris
Top achievements
Rank 1
answered on 07 Nov 2008, 02:31 PM
Thanks for the tip! It worked perfectly!
0
Steve Gray
Top achievements
Rank 1
answered on 04 Apr 2018, 12:34 PM

This link is bad. Here's the right one

https://www.telerik.com/support/code-library/show-hide-grouped-columns-on-group-ungroup-action 

0
Marin Bratanov
Telerik team
answered on 04 Apr 2018, 12:44 PM
Thank you for noticing, Steve, I fixed the link in the original post.

--Marin
Tags
Grid
Asked by
Chris
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Chris
Top achievements
Rank 1
Steve Gray
Top achievements
Rank 1
Marin Bratanov
Telerik team
Share this question
or