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

Having Issue in export to PdF

1 Answer 13 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 04 May 2016, 06:25 AM

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
                        });
                }
            }

1 Answer, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 06 May 2016, 12:01 PM
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.
Tags
General Discussions
Asked by
Ram
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Share this question
or