So I'm essentially sending filter, sorting, and other data from a page that has an iggrid. The idea is to take this info and then apply it to a WebDataGrid control.
For some reason, I can't get the filters I'm adding to the grid to apply when exporting with web document exporter. The style, the column selection all appears to show up, but the filters just won't apply. Either I get data with no filters or no data. Is there a good example or sample of how I can apply filters to a grid programatically??
Here's what I'm trying to do. I included the void that I'm using in an mvc project to download the PDF. I've also included the three options classes.
public void GetGridAsPDF(string reportName, string parameters, string columnsShown, string filterData, string sortData) { var serializer = new JavaScriptSerializer(); var hidingOptions = serializer.Deserialize<List<HidingOption>>(columnsShown); var filterOptions = serializer.Deserialize<List<FilterOption>>(filterData); var sortOptions = serializer.Deserialize<List<SortOption>>(sortData); var grid = new WebDataGrid(); grid.CssClass = "reportGrid"; grid.HeaderCaptionCssClass = "reportHeader"; grid.ItemCssClass = "reportCell"; grid.AltItemCssClass = "reportCellAlt"; grid.FooterCaptionCssClass = "reportFooter"; var exporter = new WebDocumentExporter(); var page = new System.Web.UI.Page(); page.Controls.Add(grid); page.Controls.Add(exporter); switch (reportName) { case "reportNameHere": var context = new Entities(); var data = context.sp_report_reportNameSP(int.Parse(parameters.CSVToArray()[0])).ToList(); grid.Columns.Clear(); data.Select(p => p).First().GetType().GetProperties().ToList().ForEach((p) => { var dataField = new BoundDataField(); dataField.DataFieldName = p.Name; dataField.Key = p.Name; dataField.EnableMultiline = true; dataField.HtmlEncode = true; dataField.Header.Text = ((hidingOptions.Any(h => h.key == p.Name)) ? hidingOptions.First(h => h.key == p.Name).headerText : p.Name); dataField.Hidden = ((hidingOptions.Any(h => h.key == p.Name)) ? hidingOptions.First(h => h.key == p.Name).hidden : true); grid.Columns.Add(dataField); }); grid.Behaviors.CreateBehavior<Sorting>(); grid.Behaviors.CreateBehavior<Filtering>(); grid.Behaviors.Filtering.Enabled = true; grid.Behaviors.Sorting.Enabled = true; filterOptions.ForEach((f) => { var filter = new ColumnFilter(); filter.ColumnKey = f.fieldName; switch (f.type) { case "string": filter.Condition = new RuleTextNode((TextFilterRules)Enum.Parse(typeof(TextFilterRules), f.cond, true), f.expr); break; case "number": filter.Condition = new RuleNumberNode((NumericFilterRules)Enum.Parse(typeof(NumericFilterRules), f.cond, true), (f.expr != "") ? double.Parse(f.expr) : 0); break; case "date": filter.Condition = new RuleDateNode((DateTimeFilterRules)Enum.Parse(typeof(DateTimeFilterRules), f.cond, true), (f.expr != "") ? DateTime.Parse(f.expr) : DateTime.Now); break; case "bool": filter.Condition = new RuleBoolNode((BooleanFilterRules)Enum.Parse(typeof(BooleanFilterRules), f.cond, true)); break; } grid.Behaviors.Filtering.ColumnFilters.Add(filter); }); grid.Behaviors.Sorting.SortingMode = Infragistics.Web.UI.GridControls.SortingMode.Multi; sortOptions.Where(s => s.isSorting).ToList().ForEach((s) => { grid.Behaviors.Sorting.SortedColumns.Add(grid.Columns[s.fieldName], (s.dir == "asc") ? SortDirection.Ascending : (s.dir == "desc") ? SortDirection.Descending : SortDirection.Ascending); }); grid.Visible = true; exporter.Visible = true; grid.EnableTheming = true; grid.StyleSetName = "Default"; var report = new Infragistics.Documents.Reports.Report.Report(); var section = report.AddSection(); var header = section.AddText(); header.AddContent("Report Title Here"); header.Style.Font.Size = 16f; header.Style.Font.Bold = true; header.Alignment = new Infragistics.Documents.Reports.Report.TextAlignment(Infragistics.Documents.Reports.Report.Alignment.Center); var gap = section.AddGap(); gap.Height = new Infragistics.Documents.Reports.Report.FixedHeight(20); grid.DataSource = data; grid.AutoGenerateColumns = false; grid.DataBind(); grid.Behaviors.Filtering.ApplyFilter(); exporter.ExportMode = ExportMode.Download; exporter.DownloadName = reportName + ".pdf"; exporter.Format = FileFormat.PDF; exporter.CellExporting += exporter_CellExporting; exporter.EnableStylesExport = true; exporter.DataExportMode = DataExportMode.DataInGridOnly; exporter.TargetPaperOrientation = Infragistics.Documents.Reports.Report.PageOrientation.Landscape; exporter.TargetPaperSize = Infragistics.Documents.Reports.Report.PageSizes.Legal; exporter.Export(grid, report, section); break; } } public class FilterOption { public string fieldName; public string cond; public string expr; public string logic; public string type; } public class HidingOption { public string headerText; public string key; public string dataType; public bool hidden; public int? width; } public class SortOption { public string fieldName; public bool isSorting; public string dir; }
Hello Paul Ferguson,
Thank you for posting in our forums!
We do not support using our WebForms controls in an MVC application due to the different architecture between the two.
I would recommend using the IgniteUI MVC Document Engine instead of the WebDocumentExporter.
You can find a sample using our MVC Document Engine to export an igGrid here.
If you have any further questions or concerns with this, please let me know and I will be glad to help.
I'm using WebDataGrid and WebDocumentExporter. They are both web controls. I'm just creating the controls and adding them to a page within code. These are not windows forms controls. They are the asp.net controls...
Hi Paul Ferguson,
The WebDataGrid, WebDocumentExporter, and other "Infragistics ASP.NET" controls are designed to be used in ASP.NET WebForms applications, not ASP.NET MVC applications. You can see a brief explanation on the differences between the two in our forums here.
The IgniteUI libraries and controls are designed to work within ASP.NET MVC applications. This is why I recommend using the IgniteUI Documents library.
If you need further assistance with this, please let me know.
I'm not using the grid in a view. The only thing remotely MVC is that I'm using a method on a controller. It's acting more like a service.
I'm simply creating everything on a page in memory and exporting. I can export the grid without issue. Even the css updates I did work great and show up. But for some reason even after applying filters to the grid, the exporter does not pick this up and just gives me everything. This is with dataexportmode set to DataInGridOnly.
So Here's a break down of what I'm doing.
Hi Paul,
An alternative approach you can use would be to apply the filter settings directly to your datasource before binding to the WebDataGrid instead of applying them to the WebDataGrid's filtering behavior.
We do not support usage of the WebDataGrid outside of WebForms applications since there is no ASP.NET Page LifeCycle in play. The ASP.NET controls also require to be in a Form on the page which, even in memory, may impact the behavior.
If this alternative approach does not work for you I can investigate this further if you provide an isolated sample that reproduces the issue.
Looking forward to hearing from you.