Search results

Save and Load Pivot grid Layout

You can save and load pivot grid layout by using GetPersistData and LoadPersistData methods in the EjsPivotView.

    @using Syncfusion.EJ2.Blazor.PivotView
    @using Syncfusion.EJ2.Blazor.Buttons

    <EjsButton OnClick="savedata">Save Layout</EjsButton>
    <EjsButton OnClick="loaddata">Load Layout</EjsButton>

    <EjsPivotView TValue="ProductDetails" @ref="pivot" @ref:suppressField>
        <PivotViewDataSourceSettings DataSource="@dataS" EnableSorting=true>
            <PivotViewColumns>
                <PivotViewColumn Name="Year"></PivotViewColumn>
                <PivotViewColumn Name="Quarter"></PivotViewColumn>
            </PivotViewColumns>
            <PivotViewRows>
                <PivotViewRow Name="Country"></PivotViewRow>
                <PivotViewRow Name="Products"></PivotViewRow>
            </PivotViewRows>
            <PivotViewValues>
                <PivotViewValue Name="Sold" Caption="Units Sold"></PivotViewValue>
                <PivotViewValue Name="Amount" Caption="@caption"></PivotViewValue>
            </PivotViewValues>
            <PivotViewFormatSettings>
                <PivotViewFormatSetting Name="Amount" Format="C0" UseGrouping=true></PivotViewFormatSetting>
            </PivotViewFormatSettings>
        </PivotViewDataSourceSettings>
        <PivotViewGridSettings ColumnWidth="140"></PivotViewGridSettings>
    </EjsPivotView>

    @code{
        public List<ProductDetails> data { get; set; }
        protected override void OnInitialized()
        {
            this.data = ProductDetails.GetProductData().ToList();
           //Bind the data source collection here. Refer "Assigning sample data to the pivot table" section in getting started for more details.
        }
        public string persistData;
        public async void savedata(Microsoft.AspNetCore.Components.Web.MouseEventArgs e)
        {
            persistData = await this.pivot.GetPersistData();
        }
        public async void loaddata(Microsoft.AspNetCore.Components.Web.MouseEventArgs e)
        {
            this.pivot.LoadPersistData(persistData);
        }
    }