Pivot Grid creation entirely using Code Behind

2 posts, 0 answers
  1. Krish Venugopal
    Krish Venugopal avatar
    2 posts
    Member since:
    Oct 2009

    Posted 27 Feb Link to this post

    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

     

  2. Krish Venugopal
    Krish Venugopal avatar
    2 posts
    Member since:
    Oct 2009

    Posted 01 Mar in reply to Krish Venugopal Link to this post

    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

Back to Top