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

How to export filtered data from Radgrid?

6 Answers 337 Views
Grid
This is a migrated thread and some comments may be shown as answers.
skywillnosky
Top achievements
Rank 1
skywillnosky asked on 01 Sep 2014, 08:59 AM
Hi there,

The question is similar to Radgrid export after filtering, and I follow the solution.

This

foreach (GridFilteringItem filter in radGrid.MasterTableView.GetItems(GridItemType.FilteringItem))
{
      filter.Visible = false;
}
radGrid.MasterTableView.ExportToExcel();

and this

radGrid.ExportSettings.IgnorePaging = true;
radGrid.ExportSettings.ExportOnlyData = true;
radGrid.ExportSettings.FileName = "MyFile_" + DateTime.Now.ToShortDateString();
radGrid.MasterTableView.ExportToExcel();

It doesn't work.

I still get the whole data.

Is there any property I miss?

This is my define in .aspx

<telerik:RadGrid ID="RadGrid1" runat="server" ActiveItemStyle-Wrap="false" AllowFilteringByColumn="False" AllowPaging="False" AllowSorting="True" AlternatingItemStyle-Wrap="false" AutoGenerateColumns="False"
    CellSpacing="0" CommandItemStyle-Wrap="false" DataSourceID="SqlDataSource1" EnableLinqExpressions="False" GridLines="None" HeaderStyle-Wrap="false" Height="600" ItemStyle-Wrap="false" OnPreRender="RadGrid1_PreRender"
    PagerStyle-AlwaysVisible="true" PageSize="20" SelectedItemStyle-Wrap="false" ShowGroupPanel="True" Skin="Web20" Width="1200" >
    <grouppanel text="<%$ Resources:MessageResource, MSG_RECMain_Group_Drop %>"></grouppanel>
    <groupingsettings casesensitive="false" showungroupbutton="true" />
    <clientsettings allowdragtogroup="true" enablepostbackonrowclick="false" enablerowhoverstyle="true">
        <selecting allowrowselect="true" enabledragtoselectrows="false" />
        <clientevents ongridcreated="RadGrid1_GridCreated" onrowselected="RowSelected"></clientevents>
        <resizing allowcolumnresize="True" allowresizetofit="true" allowrowresize="false" clipcellcontentonresize="true" enablerealtimeresize="false" resizegridoncolumnresize="false" />
        <scrolling allowscroll="true" usestaticheaders="true" />
    </clientsettings>
    <mastertableview allowmulticolumnsorting="False" datakeynames="PCID" datasourceid="SqlDataSource1">
        <rowindicatorcolumn visible="False"></rowindicatorcolumn>
        <expandcollapsecolumn created="True"></expandcollapsecolumn>
        <CommandItemSettings ShowExportToExcelButton="true" />
        <Columns></Columns>
    </mastertableview>
</telerik:RadGrid>

6 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 03 Sep 2014, 01:50 PM
Hi,

I have tried to replicate the behavior you describe, however I was unable to. The filtered data is exported as expected on my end. I am attaching the sample project as reference. Give it a try and let me know how it works for you.

Try using similar approach and you should be able to achieve the behavior you are looking for.

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.

 
0
skywillnosky
Top achievements
Rank 1
answered on 05 Sep 2014, 02:48 AM
Dear Viktor :

It's work in CSV, Excel, Word.

The thread I refer have something wrong in grid.AllowFilteringByColumn = true;

That is the key!!

But it still has some problem in PDF.

If I set the AllowFilteringByColumn  to True, it gives me an Exception.

The following is Exception message.

----------
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)
  at Telerik.Web.Apoc.Fo.Flow.Table.Layout(Area area)
  at Telerik.Web.Apoc.Fo.Flow.Block.Layout(Area area)
  at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area, Region region)
  at Telerik.Web.Apoc.Fo.Flow.Flow.Layout(Area area)
  at Telerik.Web.Apoc.Fo.Pagination.PageSequence.Format(AreaTree areaTree)
  at Telerik.Web.Apoc.StreamRenderer.Render(PageSequence pageSequence)
  at Telerik.Web.Apoc.Fo.FOTreeBuilder.EndElement()
  at Telerik.Web.Apoc.Fo.FOTreeBuilder.Parse(XmlReader reader)
----------

This Exception only can be fixed by set grid.ExportSettings.ExportOnlyData to True.

By the way, this exception always occured when my grid has FilterTemple.

For Example

<telerik:GridBoundColumn DataField="swTypeName" DataType="System.String"
    HeaderStyle-HorizontalAlign="Left"  HeaderStyle-Wrap="false"
    AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" 
    ShowFilterIcon="false" FilterControlAltText="Filter swTypeName column"
    HeaderText="SoftwareType" ItemStyle-HorizontalAlign="Left"
    ItemStyle-Wrap="false" SortExpression="swTypeName" UniqueName="swTypeName">
    <FilterTemplate>
        <telerik:RadComboBox ID="RadComboBoxswTypeName" Height="100px"
            Width="80px" AppendDataBoundItems="true"
            SelectedValue=
                '<%#
                    ((GridItem)Container).OwnerTableView.GetColumn("swTypeName")
                        .CurrentFilterValue
                %>'
            runat="server" OnClientSelectedIndexChanged="swTypeNameIndexChanged"
            NoWrap="True" DropDownAutoWidth="Enabled">
            <Items>
                <telerik:RadComboBoxItem Text="All" />
                <telerik:RadComboBoxItem Text="Software1"  Value="Software1"/>
                <telerik:RadComboBoxItem Text="Software2"  Value="Software2"/>
                <telerik:RadComboBoxItem Text="Software3"  Value="Software3"/>
            </Items>
        </telerik:RadComboBox>
        <telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
            <script type="text/javascript">
                function swTypeNameIndexChanged(sender, args) {
                    var tableView =
                        $find("<%#
                                ((GridItem)Container).OwnerTableView.ClientID
                            %>");
                    tableView.filter(
                            "swTypeName",
                            args.get_item().get_value(),
                            "Contains"
                        );
                }
            </script>
        </telerik:RadScriptBlock>
    </FilterTemplate>
</telerik:GridBoundColumn>



0
Viktor Tachev
Telerik team
answered on 08 Sep 2014, 10:56 AM
Hello,

The error is generally caused when there are elements with dimensions specified in percents. Note that the RadComboBox is a complex control and internally it uses dimensions in percentage. Because of this the error is shown when you are trying to export the combo.

In order to avoid the error try to set the ExportOnlyData property to true.


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.

 
0
skywillnosky
Top achievements
Rank 1
answered on 18 Sep 2014, 09:59 AM
Dear Viktor:

Thanks your suggestion, but I still have some problem. 

The filtered data from grid I exported is fine, but I can't see the filter string.

example

I entered "RDW1", "10.2" as a filter string. (Show in TS1.png)

then I exported the grid. I got a pdf file, filtered data was fine, but filter strings disappear.(Show in TS2.png)

(AllowFilteringByColumn  = true)

Did I miss something?






0
Viktor Tachev
Telerik team
answered on 23 Sep 2014, 07:56 AM
Hello,

I tried replicating the behavior shown in the screenshots, however I was unable to. I am attaching a sample project that seems to work as expected on my end - the filter string is shown in the exported file.

Give the attached sample a try and see how it works for you. Try using similar approach and you should be able to achieve the functionality you are looking for.

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.

 
0
skywillnosky
Top achievements
Rank 1
answered on 30 Sep 2014, 07:01 AM
Dear Viktor:
I found cause of the problem.

If I initial the grid SqlDataSource's property SelectCommand in OnPreRender event,

filter string will be hided after exporting as pdf file.

The solution I found is initial the SelectCommand in SqlDataSource OnInit Event

client-side

<asp:SqlDataSource ID="SqlDataSourceTest" runat="server" ConnectionString="your connstr" OnInit="OnInit_EVENT">

server-side

protected void Init_Event(object sender, EventArgs e)
{
    SqlDataSourceTest.ConnectionString = "your connstr";
    SqlDataSourceTest.SelectCommand = "your sql query";
}

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