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