In the GroupsChanging event of RadGrid, I want to count the number of columns that are currently grouped or just check to see if any grouping exists. Currently, I have it hiding the export to Excel/PDF buttons if it is a grouping action and unhiding if it is an ungrouping action. However, if there are more than one columns grouped, I still want to keep the export buttons hidden. If I do a check to see if there are any columns still grouped, I can continue to hide the export buttons. I can't seem to find any help on this. Thoughts?
Protected Sub gvAccounts_GroupsChanging(sender As Object, e As GridGroupsChangingEventArgs) Handles gvAccounts.GroupsChanging If (e.Action = GridGroupsChangingAction.Group) Then gvAccounts.AllowPaging = False gvAccounts.MasterTableView.GetColumnSafe(e.Expression.GroupByFields(0).FieldName).Visible = False gvAccounts.MasterTableView.CommandItemSettings.ShowExportToExcelButton = False gvAccounts.MasterTableView.CommandItemSettings.ShowExportToPdfButton = False ElseIf (e.Action = GridGroupsChangingAction.Ungroup) Then IF ''add some code here to check if there are any grouped columns, if false then gvAccounts.MasterTableView.CommandItemSettings.ShowExportToExcelButton = True gvAccounts.MasterTableView.CommandItemSettings.ShowExportToPdfButton = True End If gvAccounts.AllowPaging = True gvAccounts.MasterTableView.GetColumnSafe(e.Expression.GroupByFields(0).FieldName).Visible = True End IfEnd Sub8 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 27 Feb 2014, 07:42 AM
Hi Jack,
You can get the count of Grouped column in the PreRender event and you can hide the Export buttons in this event as follows:
VB:
Thanks,
Princy
You can get the count of Grouped column in the PreRender event and you can hide the Export buttons in this event as follows:
VB:
Protected Sub RadGrid1_PreRender(sender As Object, e As EventArgs) Dim count As Integer = RadGrid1.MasterTableView.GroupByExpressions.Count If count = 0 Then RadGrid1.MasterTableView.CommandItemSettings.ShowExportToExcelButton = True RadGrid1.Rebind() ElseIf count > 0 Then RadGrid1.MasterTableView.CommandItemSettings.ShowExportToExcelButton = False RadGrid1.Rebind() End IfEnd SubThanks,
Princy
0
Doug
Top achievements
Rank 1
answered on 27 Feb 2014, 03:54 PM
Thanks, Princy, this does exactly what I was wanting. However, now when I click to export either PDF or Excel, I get a message saying the file is corrupt. I'm not sure what is causing that.
0
Doug
Top achievements
Rank 1
answered on 27 Feb 2014, 04:58 PM
FYI, the error I'm getting is below. After some searching on this, it seems that it has to do with having GridDateTimeColumn along with allowing filtering, both of which I need. If I set AllowFilteringByColumn to False in the ItemCommand for exporting, then it exports fine, but I lose the filtering.
It seems to be the rebind in the solution that causes this since there was no issue in the export prior.
It seems to be the rebind in the solution that causes this since there was no issue in the export prior.
System.InvalidCastException: Unable to cast object of type 'Telerik.Web.Apoc.Layout.BlockArea' to type 'Telerik.Web.Apoc.Layout.AreaContainer'. at Telerik.Web.Apoc.Fo.Flow.BlockContainer.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.Block.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.TableCell.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.TableRow.Layout(Area area) at Telerik.Web.Apoc.Fo.Flow.AbstractTableBody.Layout(Area area)0
Princy
Top achievements
Rank 2
answered on 28 Feb 2014, 03:28 AM
Hi Jack,
Can you please try setting ExportOnlyData="true" of the ExportSettings in your RadGrid and check if the issue exists.
ASPX:
Thanks,
Princy
Can you please try setting ExportOnlyData="true" of the ExportSettings in your RadGrid and check if the issue exists.
ASPX:
<ExportSettings ExportOnlyData="true" IgnorePaging="true" ></ExportSettings>Thanks,
Princy
0
Doug
Top achievements
Rank 1
answered on 28 Feb 2014, 02:43 PM
Thanks for the reply. I should have mentioned those items already exist. Below is the entire grid.
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel><telerik:RadAjaxPanel ID="radAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" ClientEvents-OnRequestStart="requestStart"> <telerik:RadGrid ID="gvAccounts" runat="server" AllowPaging="false" AllowSorting="true" OnNeedDataSource="gvAccounts_NeedDataSource" OnItemCreated="gvAccts_ItemCreated" AutoGenerateColumns="false" AllowFilteringByColumn="true" ShowFooter="true" PageSize="50" ShowGroupPanel="true" OnItemCommand="gvAccounts_ItemCommand" MasterTableView-ShowFooter="true" EnableLinqExpressions="false" GroupingSettings-CaseSensitive="false" OnBiffExporting="gvAccounts_BiffExporting" OnPdfExporting="gvAccounts_PdfExporting" > <GroupingSettings CaseSensitive="false" /> <ExportSettings IgnorePaging="true" OpenInNewWindow="true" FileName="AccountList" ExportOnlyData="true" Excel-Format="Biff" Excel-FileExtension="xls" HideStructureColumns="true" > <Pdf AllowPrinting="true" /> </ExportSettings> <MasterTableView AutoGenerateColumns="false" AllowFilteringByColumn="true" ShowFooter="true" CommandItemDisplay="Top" AllowMultiColumnSorting="true" EnableGroupsExpandAll="true" GroupsDefaultExpanded="false" ShowGroupFooter="true"> <CommandItemSettings ShowExportToPdfButton="True" ExportToPdfImageUrl="../Images/pdficon_large.png" ExportToPdfText="" ShowExportToExcelButton="True" ShowAddNewRecordButton="false" ShowRefreshButton="false" ExportToExcelImageUrl="../Images/excel.png" ExportToExcelText="" /> <PagerStyle Mode="NextPrevAndNumeric" PageSizeLabelText="Page Size: " PageSizes="25,50,100,250,500" /> <Columns> <telerik:GridBoundColumn FilterControlWidth="40px" ItemStyle-Width="50px" DataField="COLLID" HeaderText="Coll ID" UniqueName="COLLID" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" HeaderStyle-Width="50px" DataType="System.String" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="40px" ItemStyle-Width="60px" HeaderStyle-Width="60px" DataField="CollName" HeaderText="Coll Name" UniqueName="CollName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ItemStyle-Wrap="false" DataType="System.String" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="50px" ItemStyle-Width="70px" HeaderStyle-Width="70px" DataField="ACCTID" HeaderText="AcctID" UniqueName="ACCTID" AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo" ItemStyle-Wrap="false" DataType="System.Int32" Aggregate="Count" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="40px" ItemStyle-Width="60px" HeaderStyle-Width="60px" DataField="ConName" HeaderText="Consumer" UniqueName="ConName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" ItemStyle-Wrap="false" DataType="System.String" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="40px" ItemStyle-Width="50px" HeaderStyle-Width="50px" DataField="CLID" HeaderText="CLID" UniqueName="CLID" AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo" DataType="System.Int32" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="100px" ItemStyle-Width="120px" HeaderStyle-Width="120px" DataField="ClientName" HeaderText="Client Name" UniqueName="ClientName" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" DataType="System.String" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="30px" ItemStyle-Width="50px" HeaderStyle-Width="50px" DataField="Section" HeaderText="Section" UniqueName="Section" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" Visible="false" DataType="System.String" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="30px" ItemStyle-Width="50px" HeaderStyle-Width="60px" DataField="STRATEGY" HeaderText="Strategy" UniqueName="Strategy" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" DataType="System.String" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="30px" ItemStyle-Width="50px" HeaderStyle-Width="50px" DataField="ACTSTATUS" HeaderText="Status" UniqueName="ACTSTATUS" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" DataType="System.String" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridBoundColumn> <telerik:GridDateTimeColumn FilterControlWidth="90px" ItemStyle-Width="120px" HeaderStyle-Width="125px" DataField="NextWorkDate" HeaderText="Next Work Date" DataFormatString="{0: MM/dd/yyyy hh:mm tt}" ItemStyle-Wrap="false" EnableRangeFiltering="true" AutoPostBackOnFilter="false" CurrentFilterFunction="NoFilter" PickerType="DatePicker" UniqueName="NextWorkDate" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridDateTimeColumn> <telerik:GridDateTimeColumn FilterControlWidth="90px" ItemStyle-Width="120px" HeaderStyle-Width="125px" DataField="LastWorkDate" HeaderText="Last Work Date" DataFormatString="{0: MM/dd/yyyy hh:mm tt}" ItemStyle-Wrap="false" EnableRangeFiltering="true" AutoPostBackOnFilter="false" CurrentFilterFunction="NoFilter" PickerType="DatePicker" UniqueName="LastWorkDate" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridDateTimeColumn> <telerik:GridBoundColumn FilterControlWidth="40px" ItemStyle-Width="60px" HeaderStyle-Width="60px" DataField="AMTBALANCE" HeaderText="Balance" UniqueName="AMTBALANCE" AutoPostBackOnFilter="false" CurrentFilterFunction="GreaterThanOrEqualTo" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Left" DataFormatString="{0: $#,##0;-$#,##0}" ShowFilterIcon="true" Aggregate="Sum" FilterControlToolTip="Tip: To search between amounts enter both amounts with a space like this: 50 100 and use the 'Between' filter."> </telerik:GridBoundColumn> <telerik:GridBoundColumn FilterControlWidth="40px" ItemStyle-Width="60px" HeaderStyle-Width="60px" DataField="NextDueAmt" HeaderText="Next Due Amt" UniqueName="NextDueAmt" AutoPostBackOnFilter="false" CurrentFilterFunction="GreaterThanOrEqualTo" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Left" DataFormatString="{0: $#,##0;-$#,##0}" ShowFilterIcon="true" FilterControlToolTip="Tip: To search between amounts enter both amounts with a space like this: 50 100 and use the 'Between' filter."> </telerik:GridBoundColumn> <telerik:GridDateTimeColumn FilterControlWidth="90px" ItemStyle-Width="120px" HeaderStyle-Width="125px" DataField="NextDueDate" HeaderText="Next Due Date" DataFormatString="{0: MM/dd/yyyy}" ItemStyle-Wrap="false" EnableRangeFiltering="true" AutoPostBackOnFilter="false" CurrentFilterFunction="NoFilter" PickerType="DatePicker" UniqueName="NextDueDate" ItemStyle-HorizontalAlign="Left" ShowFilterIcon="true"> </telerik:GridDateTimeColumn> </Columns> <GroupByExpressions> <telerik:GridGroupByExpression> <GroupByFields> <telerik:GridGroupByField FieldName="Section" SortOrder="Ascending" ></telerik:GridGroupByField> </GroupByFields> <SelectFields> <telerik:GridGroupByField FieldName="Section"></telerik:GridGroupByField> </SelectFields> </telerik:GridGroupByExpression> </GroupByExpressions> </MasterTableView> <GroupingSettings ShowUnGroupButton="true" RetainGroupFootersVisibility="true" /> <ClientSettings EnableRowHoverStyle="true" ReorderColumnsOnClient="false" AllowDragToGroup="true" AllowGroupExpandCollapse="true" AllowColumnsReorder="false"> <Selecting AllowRowSelect="true" /> <Resizing AllowRowResize="true" AllowColumnResize="true" EnableRealTimeResize="true" ResizeGridOnColumnResize="true" AllowResizeToFit="true" /> </ClientSettings> </telerik:RadGrid></telerik:RadAjaxPanel>0
Princy
Top achievements
Rank 2
answered on 03 Mar 2014, 03:07 AM
Hi Jack,
Please try the below code snippet in the ItemCommand event.
VB:
Thanks,
Princy
Please try the below code snippet in the ItemCommand event.
VB:
Protected Sub RadGrid1_ItemCommand(sender As Object, e As GridCommandEventArgs) If e.CommandName = RadGrid.ExportToPdfCommandName Then RadGrid1.MasterTableView.AllowFilteringByColumn = False If Not RadGrid1.ExportSettings.IgnorePaging Then RadGrid1.Rebind() End If End IfEnd SubThanks,
Princy
0
Doug
Top achievements
Rank 1
answered on 04 Mar 2014, 03:25 PM
That solution is similar to what I mentioned earlier in the thread that does work, but I loose filtering which I can't have. At this point, I'm just not going to dynamically hide the export buttons.
Thanks
Thanks
0
Princy
Top achievements
Rank 2
answered on 05 Mar 2014, 05:00 AM
Hi Jack,
I was not able to replicate the issue at my end. The filtering worked as expected after the Export. Below is the sample code snippet that I tried.
ASPX:
VB:
Thanks,
Princy
I was not able to replicate the issue at my end. The filtering worked as expected after the Export. Below is the sample code snippet that I tried.
ASPX:
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server"></telerik:RadAjaxLoadingPanel><telerik:RadAjaxPanel ID="radAjaxPanel1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" ClientEvents-OnRequestStart="onRequestStart"> <telerik:RadGrid ID="gvAccounts" runat="server" AllowPaging="true" AllowSorting="true" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" AllowFilteringByColumn="true" ShowGroupPanel="true" EnableLinqExpressions="false" GroupingSettings-CaseSensitive="false" OnItemCommand="gvAccounts_ItemCommand" OnPreRender="gvAccounts_PreRender"> <ExportSettings IgnorePaging="true" OpenInNewWindow="true" ExportOnlyData="true" Excel-Format="Biff" Excel-FileExtension="xls" HideStructureColumns="true"> </ExportSettings> <MasterTableView CommandItemDisplay="Top" EnableGroupsExpandAll="true"> <CommandItemSettings ShowExportToPdfButton="True" ShowExportToExcelButton="True" ShowAddNewRecordButton="false" ShowRefreshButton="false" /> <Columns> <telerik:GridBoundColumn DataField="OrderID" HeaderText="OrderID" AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="CustomerID" HeaderText="CustomerID" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo"> </telerik:GridBoundColumn> <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" AutoPostBackOnFilter="true" CurrentFilterFunction="Contains"> </telerik:GridBoundColumn> <telerik:GridDateTimeColumn FilterControlWidth="90px" DataField="OrderDate" HeaderText="OrderDate" DataFormatString="{0: MM/dd/yyyy hh:mm tt}" EnableRangeFiltering="true" CurrentFilterFunction="NoFilter" PickerType="DatePicker"> </telerik:GridDateTimeColumn> <telerik:GridDateTimeColumn FilterControlWidth="90px" DataField="RequiredDate" HeaderText="RequiredDate" DataFormatString="{0: MM/dd/yyyy hh:mm tt}" EnableRangeFiltering="true" PickerType="DatePicker"> </telerik:GridDateTimeColumn> </Columns> <GroupByExpressions> <telerik:GridGroupByExpression> <GroupByFields> <telerik:GridGroupByField FieldName="ShipCountry" SortOrder="Ascending"></telerik:GridGroupByField> </GroupByFields> <SelectFields> <telerik:GridGroupByField FieldName="ShipCountry"></telerik:GridGroupByField> </SelectFields> </telerik:GridGroupByExpression> </GroupByExpressions> </MasterTableView> <GroupingSettings ShowUnGroupButton="true" /> <ClientSettings EnableRowHoverStyle="true" AllowDragToGroup="true" AllowGroupExpandCollapse="true"> <Selecting AllowRowSelect="true" /> </ClientSettings> </telerik:RadGrid></telerik:RadAjaxPanel>VB:
Protected Sub gvAccounts_PreRender(sender As Object, e As EventArgs) Dim count As Integer = gvAccounts.MasterTableView.GroupByExpressions.Count If count = 0 Then gvAccounts.MasterTableView.CommandItemSettings.ShowExportToExcelButton = True gvAccounts.MasterTableView.CommandItemSettings.ShowExportToPdfButton = True gvAccounts.Rebind() ElseIf count > 0 Then gvAccounts.MasterTableView.CommandItemSettings.ShowExportToExcelButton = False gvAccounts.MasterTableView.CommandItemSettings.ShowExportToPdfButton = False gvAccounts.Rebind() End IfEnd SubProtected Sub gvAccounts_ItemCommand(sender As Object, e As GridCommandEventArgs) If e.CommandName = RadGrid.ExportToPdfCommandName Then gvAccounts.MasterTableView.AllowFilteringByColumn = False If Not gvAccounts.ExportSettings.IgnorePaging Then gvAccounts.Rebind() End If End IfEnd SubThanks,
Princy