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

Pivot Grid creation entirely using Code Behind

1 Answer 31 Views
PivotGrid
This is a migrated thread and some comments may be shown as answers.
Krish Venugopal
Top achievements
Rank 1
Krish Venugopal asked on 27 Feb 2019, 06:01 PM

Hi,

I have managed to successfully create Pivot Grids from code behind, the definition of the pivot grid, rows, columns and aggregates and filters are stored in SQL Server, I am able to easily create the grid at run time and display it. The sorting, column filters, row filters all work well. However the PivotGridReportFilterField defined when clicked fail with 

 

[NullReferenceException: Object reference not set to an instance of an object.] Telerik.Web.UI.PivotGridFilterWindow.InitializeControls() +904 Telerik.Web.UI.PivotGridFilteringManager.CreateFilterWindow() +90 Telerik.Web.UI.PivotGridFilteringManager.SetUpFilterWindowControls() +14 Telerik.Web.UI.RadPivotGrid.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +723

 

In the code behind, I construct the grid as follows:

foreach (var def in defList)
                {
                    if (def.ReportFieldType == (int) ReportFieldType.RowFieldForTable)
                    {
                        // Define Rows                         var rowField = new PivotGridRowField();
                        PivotGrid.Fields.Add(rowField);
                        rowField.DataField = def.Fieldname;
                        rowField.UniqueName = def.Fieldname.Replace(" "string.Empty);
                    }
                    else if (def.ReportFieldType == (int) ReportFieldType.ColumnFieldForTable)
                    {
                        // Define Columns                         var colField = new PivotGridColumnField();
                        PivotGrid.Fields.Add(colField);
                        colField.DataField = def.Fieldname;
                        colField.UniqueName = def.Fieldname.Replace(" "string.Empty);
                    }
                    else if ((def.ReportFieldType == (int) ReportFieldType.CountFieldForTable) ||                             (def.ReportFieldType == (int) ReportFieldType.AverageFieldForTable) ||                             (def.ReportFieldType == (int) ReportFieldType.SumFieldForTable))
                    {
                        //Define Aggregrates                         var aggregateField = new PivotGridAggregateField();
                        PivotGrid.Fields.Add(aggregateField);
                        aggregateField.DataField = def.Fieldname;
                        aggregateField.UniqueName = def.Fieldname.Replace(" "string.Empty);
  
                        if (def.ReportFieldType == (int) ReportFieldType.CountFieldForTable) aggregateField.Aggregate = PivotGridAggregate.Count;
                        if (def.ReportFieldType == (int) ReportFieldType.AverageFieldForTable) aggregateField.Aggregate = PivotGridAggregate.Average;
                        if (def.ReportFieldType == (int) ReportFieldType.SumFieldForTable) aggregateField.Aggregate = PivotGridAggregate.Sum;
                    }
                    else if (def.ReportFieldType == (int) ReportFieldType.FilterFields)
                    {
                        var filterField = new PivotGridReportFilterField();
                        PivotGrid.Fields.Add(filterField);
                        filterField.DataField = def.Fieldname;
                        filterField.UniqueName = def.Fieldname.Replace(" "string.Empty);
                        //filterField.FilterType = PivotGridReportFilterActionType.Includes;                     }
                }

 

Any help in resolving this issue would be much appreciated.

Thanks

 

1 Answer, 1 is accepted

Sort by
0
Krish Venugopal
Top achievements
Rank 1
answered on 01 Mar 2019, 08:46 AM

Hi,

If it helps,What I have noticed is that if I use List<object> as a data source for the Pivot Grid, the Pivot Filter works as expected. However in the Need Datasource  event if I use a dynamic SQL and populate the pivot grid and then click on the filter that is when the filter fails to load, that is the filter window does not load.

Thanks

Tags
PivotGrid
Asked by
Krish Venugopal
Top achievements
Rank 1
Answers by
Krish Venugopal
Top achievements
Rank 1
Share this question
or