OlapGrid without cube

Hi,

I quite like some of the functionality that the OlapGrid offers with regards to being able to natively display data in a Matrix-style grid.  However, it appears that to use an OlapGrid I need to bind it to an offline or online Cube of some sort.

Would you recommend using the SyncFusion data grid in this instance, instead?  Admittedly, I'm struggling to get the same look and feel I want from the data grid but perhaps I just need to spend more time with it.

Thanks,

Karl


16 Replies

SG Santhosh Govindasamy Syncfusion Team August 13, 2024 10:07 AM UTC

Hi Karl Grambow,

Thank you for reaching out.


It seems you are looking to use the DataGrid control but with a look and feel like the OlapGrid. To better assist you, could you please clarify your specific requirements? 


We maintain both the DataGrid and PivotGrid controls, each serving specific purposes for managing and displaying data collections. We would like to provide you with an overview of both. Please use it according to your needs.


DataGrid:

The SfDataGrid control for WPF is primarily designed to display data in rows and columns. It offers features such as sorting, filtering, editing, and grouping, making it suitable for managing and presenting tabular data.


PivotGrid:

The PivotGrid is a more specialized control for summarizing and analyzing large datasets through grouping and filtering. It allows you to rearrange data dynamically by dragging fields between rows, columns, and values, offering different perspectives and insights. This makes it ideal for creating dynamic reports similar to what you might achieve with an OlapGrid.


For your reference, I have attached user guide links for both the DataGrid and PivotGrid controls.

https://help.syncfusion.com/wpf/datagrid/overview

https://help.syncfusion.com/wpf/pivot-grid/overview


Thanks for the cooperation, we look forward your response.

Regards,
Santhosh.G




KG Karl Grambow August 13, 2024 02:24 PM UTC

Hi Santosh,


In simple terms I'm trying to replicate the Power BI matrix visual, which consists of rows, (optionally) columns and cells.


The rows and columns represent dimensions and the cells represents measures.  I can approximate what I need using the data grid but because the data grid only consists of rows and columns, the whole grid is represented by a row.  


For example, I might want to display total sales by Category and Subcategory (rows) and MonthYear (columns).  In this example, the Category row can be expanded to show subcategories.  I realise that this is potentially achievable using a data grid and groups and summaries but it feels like a more natural fit to use an OlapGrid.  The problem is, the data in question isn't in a cube.


Regards,





SG Santhosh Govindasamy Syncfusion Team August 14, 2024 03:19 PM UTC

Hi Karl Grambow,

We are currently analyzing the scenario you reported. We need time to validate it, and we will provide an update on or before August 16, 2024.


Regards,
Santhosh.G



GS Gokul S Subramani Syncfusion Team August 16, 2024 01:37 PM UTC

Hi Karl,


We apologize for the inconvenience. Currently, in SfDataGrid, we do not have direct support for binding to an offline or online cube like an OlapGrid. While trying to implement a workaround based on your requirements, we are facing some little bit difficulties. We are analyzing the reported scenario and need more time to validate it. We will provide an update by August 20, 2024.


Thank you for your understanding and cooperation.


Best Regards,

Gokul S



KG Karl Grambow August 16, 2024 01:48 PM UTC

Hi Gokul,


No problem.  Thanks for the update.

Just to be clear, the source data is coming from a SQL Server database so I don't have access to an offline or online cube.  So I wouldn't be able to bind any cube to sfDataGrid.

Regarding the OlapGrid.  Is it possible to create an abstraction of an online or offline Cube in C# and bind this abstraction to the OlapGrid?


Thanks again for the update and the amazingly good support that you offer.


Regards,


Karl



SG Santhosh Govindasamy Syncfusion Team August 19, 2024 01:02 PM UTC

Hi Karl Grambow,


Yes, it is absolutely possible to create an abstraction for both online and offline Cubes in C# and bind it to the OlapGrid. This can be achieved by defining a common abstraction layer that represents the structure and data of the Cube, regardless of the data source. Here’s how it works:

  1. Create an Abstract Base Class: Define a base class that encapsulates the common functionalities, such as managing the OlapDataManager and setting up OlapReports.
  2. Implement Concrete Classes: Create specific classes for online and offline Cubes that inherit from this base class. Each class will handle the connection and data retrieval according to the source (e.g., an online server or a local file).
  3. Bind to OlapGrid: The abstraction layer allows you to easily bind the data to the OlapGrid, enabling a seamless experience whether the data is coming from an online or offline source.

 

This approach provides flexibility and maintainability, allowing you to switch between data sources without altering the core logic of your application.

 

Attached is a simple sample for your reference. Please take a look at it.


Regards,
Santhosh.G


Attachment: Olap_Grid_a0380ec9.zip


KG Karl Grambow August 19, 2024 03:47 PM UTC

Hi Santhosh,


Thanks for that and thanks for the sample.  I'll take a closer look at it but on first inspection it appears that, in order to create a _cubeManager instance you need to provide a connection string to an online or offline cube.  But what if I don't have a cube?


Regards,


Karl



SG Santhosh Govindasamy Syncfusion Team August 20, 2024 01:16 PM UTC

Hi Karl Grambow,

Thank you for your response.

To proceed further, as you mentioned in your previous update, the data was coming from a SQL Server database. That's why we prepared the sample based on the abstraction. However, in your last update, you mentioned that you don't have a cube, by which we assume you mean a connection string. Without a connection string, we won't be able to bind data to the OLAP grid.

Could you please clarify your requirements in more detail? This will help us better understand your needs and provide the most appropriate solution.

Thank you for your cooperation. We look forward to your response.


Regards,
Santhosh.G



KG Karl Grambow August 20, 2024 03:55 PM UTC

Hi Santhosh,


Apologies, I should have been clearer on my situation.  I currently have some data in a SQL Server database (standard database, not a cube).


Ultimately, I want to display sales data, by category and subcategory (rows) and by MonthYear, columns.  I'm pulling the data out of the SQL Server tables as follows:


select sum(s.sales) as total_sales, c.category, c.subcategory, d.month_year
from fact_sales s
join dim_date d on d.date = s.date
join dim_category c on c.category_id = s.category_id;


Sorry for the confusion.


Regards,



SG Santhosh Govindasamy Syncfusion Team August 21, 2024 02:47 PM UTC

Hi Karl Grambow,

We would like to inform you that Syncfusion do not offer direct guidelines for creating a Cube using a standard database. However, you can create a cube from database with below link for your reference. If this is helpful, kindly create the Cube and use it to the OLAP grid.


https://www.cdata.com/kb/tech/ssas-ado-ssas.rst


Regards,

Santhosh.G




KG Karl Grambow August 21, 2024 03:36 PM UTC

Hi Santhosh,


Thanks for the link.  I don't want to create a cube.  I just want to know whether I can display data in a matrix-style (pivot grid) using either the sfDataGrid or the sfPivotGrid.  It seems that the sfPivotGrid won't work because it requires the data to be in a cube.


So the question is, can I use the sfDataGrid to display this kind of data in a matrix-style, with category and subcategory as rows, MonthYear as columns and the cells containing total_sales?


The trick here is in recognising that we don't know in advance how many columns there'll be because it depends on the number of MonthYear values we return.


Thanks again,


Karl




SP Sreemon Premkumar Muthukrishnan Syncfusion Team August 22, 2024 01:32 PM UTC

Hi Karl Grambow,


Based on your latest update, you need to display data in a matrix style with categories, subcategories, and month-year, with a UI similar to an OLAP grid that includes the ability to expand categories. We recommend using the PivotGridControl for this purpose. One correction to your latest update is that you don’t need a cube to load data into the PivotGridControl. You can use a table fetched from the SQL database and load it directly into the PivotGridControl. Additionally, you do not need to know the number of columns available in the database beforehand; the control will automatically generate columns based on the available column.

Here, we have used a table structured as follows:


Please find the code snippet and image reference below:

Code Snippet:

public MainWindow()

{

    InitializeComponent();

    dataTable = new DataTable();

    string connectionString = "Your_ConnectionString";

    using (SqlConnection connection = new SqlConnection(connectionString))

    {

        string query = "SELECT * FROM PivotGridSource";

        connection.Open();

        // Create a SqlCommand to execute the query

        using (SqlCommand command = new SqlCommand(query, connection))

        {

            // Create a SqlDataAdapter to fill the DataTable

            using (SqlDataAdapter adapter = new SqlDataAdapter(command))

            {

                // Fill the DataTable with the results of the query

                adapter.Fill(dataTable);

            }

        }

    }

    pivotGrid.ItemSource = dataTable;

}


Image Reference:


We have prepared a sample based on your requirements. Please find it attached.

If this solution does not meet your needs, we will need some details about the column structure of the table in the SQL database, such as how the columns and their values are organized. We understand you may not know the exact number of columns, but could you please confirm if the table you have is structured as shown below? If not, please provide details about the column structure in your database, if possible.

Category

Sub category

June 2024

July 2024

August 2024

September 2024

 

 

 

 

 

 


Regards,
Sreemon Premkumar M.


Attachment: PivotGridControl_WPF_481124ad.zip


KG Karl Grambow August 22, 2024 04:25 PM UTC

Hi Sreemon,


Thanks for the suggestion and the provided sample.  That's amazing and looks exactly like what I need, and the column structure you suggested is exactly right.


I'll take a look at this and will try to implement it.


Thanks,


Karl



KG Karl Grambow August 23, 2024 09:40 AM UTC

Hi Sreemon,


I just wanted to follow up on this and let you know that I'm successfully using the PivotGrid and it gives me what I need.  However, I have few implementation questions that I was hoping you could help with.

I'm loading in 20,000 plus records and so:


  1. In order to improve performance I've set the AutoSizeOption to "None" and I've set EnableOnDemandCalculations to "True".  Is it possible to allow the user to manually resize rows and columns?
  2. Is it possible to have all rows collapsed by default?  I've tried gridSpendByCategory.CollapseAllGroup() but this fails with a null reference on InternalGrid.
  3. I've set the SortOption to "All" so that I can sort by the Total field but if I sort by the Total field, it doesn't sort (see image below).
  4. I tried to set the ShowSubTotal to "False" and curiously, this makes performance worse.  I'd expect it actually improve performance given that we're removing the subtotal.

I've included the XAML below:

<syncfusion:PivotGridControl x:Name="gridSalesByCategory" Grid.Row="2" Grid.RowSpan="8"
                             ItemSource="{Binding SalesByCategory}"


                             AutoSizeOption="None"
                             SortOption="All"


                             >


    <syncfusion:PivotGridControl.PivotRows>
        <syncfusion1:PivotItem ShowSubTotal="False" FieldHeader="Category" FieldMappingName="Category" TotalHeader="Total" />
        <syncfusion1:PivotItem ShowSubTotal ="False" FieldHeader="Subcategory" FieldMappingName="SubCategory" TotalHeader="Total" />
        <syncfusion1:PivotItem ShowSubTotal="False" FieldHeader="Region" FieldMappingName="Region" TotalHeader="Total" />
        <syncfusion1:PivotItem ShowSubTotal="False" FieldHeader="Product" FieldMappingName="Product" TotalHeader="Total" />
    </syncfusion:PivotGridControl.PivotRows>


    <syncfusion:PivotGridControl.PivotCalculations>
        <syncfusion1:PivotComputationInfo AllowSort="True" FieldName="Spend" Format="C" SummaryType="Sum"/>
        <!--<syncfusion:PivotComputationInfo CalculationName="Total" FieldName="Quantity" SummaryType="Count" />-->
    </syncfusion:PivotGridControl.PivotCalculations>


</syncfusion:PivotGridControl>

Image_6594_1724405826462


SP Sreemon Premkumar Muthukrishnan Syncfusion Team August 26, 2024 06:00 PM UTC

Hi Karl Grambow,

We are currently checking your requirements. We need some time to validate it, and we will update you further details on or before August 28, 2024.

We appreciate your patience until then. 

Regards,

Sreemon Premkumar M. 



SG Santhosh Govindasamy Syncfusion Team August 28, 2024 01:47 PM UTC

Hi Karl Grambow,


S.No

Query

Response

1

In order to improve performance I've set the AutoSizeOption to "None" and I've set EnableOnDemandCalculations to "True".  Is it possible to allow the user to manually resize rows and columns?

 

Yes, it is possible to manually resize rows and columns. To allow users to resize columns manually, you need to enable the AllowResizeColumns property. Similarly, to enable row resizing, the AllowResizeRows property should be set to true.

 

For your convenience, I’ve attached a link to the User Guide that covers handling resizing for columns and rows.
 

https://help.syncfusion.com/wpf/pivot-grid/how-to/resizing-columns-and-rows-in-pivotgrid

 

2

Is it possible to have all rows collapsed by default?  I've tried gridSpendByCategory.CollapseAllGroup() but this fails with a null reference on InternalGrid.

 

Yes, it is possible to have all rows collapsed by default during the initial load. You are correctly using the CollapseAllGroup() method, but to avoid the NullReferenceException related to InternalGrid, you should invoke this method inside the PivotGrid's Loaded event.

 

Here’s a code snippet for reference:

public MainWindow()

{

     InitializeComponent();

     pivotGrid.Loaded += PivotGrid_Loaded;

     pivotGrid.ItemSource = ProductSales.GetSalesData();

     pivotGrid.PivotEngine.EnableOnDemandCalculations = true;

     pivotGrid.AllowResizeColumns = true;

     pivotGrid.AllowResizeRows = true;

    

     

 }

private void PivotGrid_Loaded(object sender, RoutedEventArgs e)

{

     pivotGrid.CollapseAllGroup();

}

 

This will ensure that all rows are collapsed when the grid is fully loaded.

3

I've set the SortOption to "All" so that I can sort by the Total field but if I sort by the Total field, it doesn't sort (see image below).

 

Thank you for sharing the image reference.

Based on the provided image, it seems that the sorting you applied to the "Total" field in the "Spend" column is not behaving as expected. We’d like to clarify that sorting in this scenario is applied within each group rather than across the entire "Spend" column. This means that the sorting operation is performed group-wise, rather than sorting all rows globally by the "Total" field. The sorting has been correctly applied according to the reference image.

 

 

4

I tried to set the ShowSubTotal to "False" and curiously, this makes performance worse.  I'd expect it actually improve performance given that we're removing the subtotal.

 

Based on the information provided, we attempted to replicate the performance issue by setting ShowSubTotal to False, but we did not observe any performance delays; it worked as expected. Since we couldn't replicate the issue with the given details, could you please provide more information about the performance problem? Specifically, let us know what actions you perform when you experience the performance issue. This information will help us investigate further.


Regards,
Santhosh.G


Loader.
Up arrow icon