Having Issue in export to PdF

2 posts, 0 answers
  1. Ram
    Ram avatar
    2 posts
    Member since:
    Mar 2016

    Posted 04 May Link to this post

    I am trying to export filtered records from radgrid.But it was importing all the records those are in my grid.

    Please let me know how can i achieve this.here is the code snippet.

     string extension = "pdf";
                rgEquipmentTracking.ElementExporting -= rgEquipmentTracking_ElementExporting;
                rgEquipmentTracking.ElementExporting += rgEquipmentTracking_ElementExporting;            
                SaveFileDialog dialog = new SaveFileDialog()
                {
                    DefaultExt = extension,
                    Filter = String.Format("{1} files (.{0})|*.{0}|All files (.*)|*.*", extension, "Pdf"),
                    FilterIndex = 1
                };
                var grid = new RadGridView()
                {
                    
                    ItemsSource = rgEquipmentTracking.ItemsSource,
                    RowIndicatorVisibility = Visibility.Collapsed,
                    ShowGroupPanel = false,
                    CanUserFreezeColumns = false,
                    IsFilteringAllowed = true,
                    AutoExpandGroups = true,
                    AutoGenerateColumns = false,
                    Margin = new Thickness(30, 30, 30, 30),
                    ShowColumnFooters = true,

                    EnableRowVirtualization = true
                };
                
                foreach (var column in rgEquipmentTracking.Columns.OfType<GridViewDataColumn>())
                {
                    if (column.IsVisible == true && column.UniqueName != "ViewDetail")
                    {
                        var newColumn = new GridViewDataColumn();
                        newColumn.DataMemberBinding = new System.Windows.Data.Binding(column.UniqueName);
                        grid.Columns.Add(newColumn);
                        if (column.UniqueName == "ItemDate")
                        {
                            newColumn.UniqueName = "Sign Out Date";
                            newColumn.Header = "Sign Out Date";
                            newColumn.DataMemberBinding.StringFormat = "{0:dd/MM/yyyy}";
                        }
                    }
                }


                StyleManager.SetTheme(grid, StyleManager.GetTheme(grid));
                if (dialog.ShowDialog() == true)
                {

                    using (Stream stream = dialog.OpenFile())
                    {     
                        
                        grid.ExportToPdf(stream,
                            new GridViewPdfExportOptions()
                            {
                                ExportDefaultStyles = true,
                                ShowColumnFooters = true,
                                ShowColumnHeaders = true,
                                ShowGroupFooters = true,
                                AutoFitColumnsWidth = true,
                                PageOrientation = PageOrientation.Landscape
                            });
                    }
                }

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    280 posts

    Posted 06 May Link to this post

    Hello Ram,

    By default, the ExportToPdf method of RadGridView is working with the Items collection of the control. When you apply filtering on the RadGridView, this collection should contain only the items that match the filtering criteria. I have tested this behavior and it is working as expected at my end. I have added a sample project which you can check. 

    In the code sample provided, I don`t see how you are filtering the grid. Would it be possible to modify the sample that I have provided so that the undesired behavior is present? Eventually, I can check it and update you with more information on what might be causing the issue in your case.

    Regards,
    Stefan Nenchev
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top