We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Pivot table save and load report configurations from external data source

Hi,

I am using Pivot Table table Toolbar to save/load reports in current websocket session.

https://blazor.syncfusion.com/demos/pivot-table/toolbar?_gl=1*fgvr8l*_ga*OTUxMTE5MjcxLjE2NDI1MjEyNjg.*_ga_WC4JKKPHH0*MTY3MDIzMDQ4NC4xODMuMS4xNjcwMjMxNzA3LjAuMC4w&_ga=2.20385722.346857456.1670077065-951119271.1642521268


The feature that I need is to save user's pivot table configurations - what you call as "report" to a database; and when user come back, load the saved reports to the PivotTable.

I've not found evident API in SfPivotView/Toolbar.

Is it possible to achieve that ? If so, can you please provide a sample ?

Thx!

Yi


7 Replies

AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team December 6, 2022 11:56 AM UTC

Hi Yi Han,


To store and load reports using toolbar options, we don't use API. We can save and load the pivot report at the sample level using the SaveReport and LoadReport events. Please refer the below code example and sample.


Code Example:

<SfPivotView TValue="ProductDetails">

    <PivotViewEvents TValue="ProductDetails" SaveReport="savereport" LoadReport="loadreport"></PivotViewEvents>

</SfPivotView>

 

@code {

//save the report using SaveReport event

    public void savereport(SaveReportArgs args)

    {

        var i = 0;

        bool isSaved = false;

        for (i = 0; i < this.reportName.Count; i++)

        {

            if (this.reportName[i] == args.ReportName)

            {

                this.report[i] = args.Report;

                isSaved = true;

            }

        }

        if (args.Report != null && !(isSaved))

        {

            this.report.Add(args.Report);

            this.reportName.Add(args.ReportName);

        }

 

    }

 

//to load the selected report.

    public void loadreport(LoadReportArgs args)

    {

        var i = 0;

        var j = 0;

        for (i = 0; i < this.reportName.Count; i++)

        {

            if (this.reportName[i] == args.ReportName)

            {

                j = i;

            }

        }

        this.pivot.LoadPersistDataAsync(this.report[j]);

    }

}


Meanwhile, we have prepared a sample for your reference.


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PivotTable1533777045


Please see the below UG document for more information on the “toolbar” events.


Document: https://blazor.syncfusion.com/documentation/pivot-table/tool-bar#events


Regards,

Angelin Faith Sheeba



YH Yi Han December 7, 2022 10:51 AM UTC

Hi  Angelin Faith Sheeba


Thx for your reply.


... But this does fit my requirement. The way your sample is doing, does not persists the report configuration. i.e, you close the browser tab then open a new one,  the pivot table report is gone - user have to reconfigure the report.  <-- not handy!

What I want, as said in the initial question, is saving the report configuration in a persistent data store, each time the user open pivot table page, programmatically rebuild the report automatically. <- the functionality that is possible in ASPNET Core EJ2 (https://www.syncfusion.com/forums/160976/save-and-load-report-of-pivot-report-with-web-api ) 


Is this more clear? 

Thx!

Yi



AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team December 8, 2022 11:35 AM UTC

Hi Yi Han,


We are validating this query at our end and will provide further details within two business days (Dec 12, 2022). 


Regards,

Angelin Faith Sheeba.



AP AngelinFaithSheeba PaulvannanRajadurai Syncfusion Team December 12, 2022 03:55 PM UTC

Hi Yi Han,

We are preparing sample as per your requirement and we will provide further details tomorrow (Dec 13, 2022).



RG Rajeshkannah G Syncfusion Team December 13, 2022 12:29 PM UTC

Hi Yi Han


We've prepared a sample for saving and loading reports from a SQL Server database based on your requirements. For more information, please see the sample link below. 


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Pivot-DB-415759584


Please let us know if you have any concerns. 


Regards, 

Rajeshkannah G.



YH Yi Han January 6, 2023 02:23 PM UTC

Hi Rajeshkannah ,


thanks for the sample.

I am also trying using bool: EnablePersistence

https://blazor.syncfusion.com/documentation/pivot-table/state-persistence


with your above attached sample, add EnablePersistence="true" ID="hello-world" to your pivotview

I do see local storage is used - but the persistent feature does not work. i.e, refresh the page & move to another page then come back -> expected state is lost!





RG Rajeshkannah G Syncfusion Team January 9, 2023 12:35 PM UTC

Hi Yi,


We created a Pivot Table sample that saves and loads reports from a database based on your requirements, which we shared in our previous update. So, even if EnablePersistense is enabled, the Pivot Table will always load the last saved report from the database, because the persistence report is always saved in the browser's local storage. You can, however, retrieve the persisted data and load the Pivot table by using the Destroyed event and saving the persist data report to Database. Please see the code example below.


Code Example

<SfPivotView>

<PivotViewEvents TValue="Order" Destroyed=="Destroyed" > </PivotViewEvents>

</SfPivotView>

 

public async void Destroyed()

    {

        string persistReport = await Pivot.GetPersistDataAsync();

        SaveReportToDB("Sample Report",persistReport );

    }

 


Meanwhile we have prepared a sample for your reference.


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/blazor-pivot-sqldatabinding-1954873876


Kindly let us know if you have any concerns.


Regards,

Rajeshkannah G


Loader.
Live Chat Icon For mobile
Up arrow icon