Search results

Toolbar

Toolbar option allows to access the frequently used features like switching between pivot table and pivot chart, changing chart types, conditional formatting, exporting, etc… with ease at runtime. This option can be enabled by setting the ShowToolbar property in EjsPivotView class to true. The Toolbar property in EjsPivotView class accepts the collection of built-in toolbar options.

The following table shows built-in toolbar options and its actions.

Built-in Toolbar Options Actions
New Creates a new report
Save Saves the current report
Save As Save as current report
Rename Renames the current report
Delete Deletes the current report
Load Loads any report from the report list
Grid Shows pivot table
Chart Shows a chart in any type from the built-in list
Exporting Exports the pivot table as PDF/Excel/CSV and the pivot chart as PDF and image
Sub-total Shows or hides sub totals
Grand Total Shows or hides grand totals
Conditional Formatting Shows the conditional formatting pop-up to apply formatting
Field List Shows the fieldlist pop-up

Events

FetchReport

The event FetchReport is triggered when dropdown list is clicked in the toolbar in-order to retrieve and populate saved reports. It has following parameter - ReportName. This event allows user to fetch the report names from local storage and populate the dropdown list.

LoadReport

The event LoadReport is triggered when a report is selected from the dropdown list in the toolbar. It has following parameters - Report and ReportName. This event allows user to load the selected report to the pivot table.

NewReport

The event NewReport is triggered when the new report icon is clicked in the toolbar. It has following parameter - Report. This event allows user to create new report and add to the report list.

RenameReport

The event RenameReport is triggered when rename report icon is clicked in the toolbar. It has following parameters - Rename, Report and ReportName. This event allows user to rename the selected report from the report list.

RemoveReport

The event RemoveReport is triggered when remove report icon is clicked in the toolbar. It has following parameters - Report and ReportName. This event allows user to remove the selected report from the report list.

SaveReport

The event SaveReport is triggered when save report icon is clicked in the toolbar. It has following parameters - Report and ReportName. This event allows user to save the altered report to the report list.

The order of toolbar options can be changed by simply moving the position of items in the ToolbarItems collection. Also if end user wants to remove any toolbar option from getting displayed, it can be simply ignored from adding into the ToolbarItems collection.

    @using Syncfusion.EJ2.Blazor.PivotView

    <EjsPivotView TValue="ProductDetails" ShowFieldList="true" ShowToolbar="true" Toolbar="@toolbar" AllowConditionalFormatting="true" AllowPdfExport="true" AllowExcelExport="true">
        <PivotViewDisplayOption Primary=Primary.Table View=View.Both></PivotViewDisplayOption>
            <PivotViewDataSourceSettings DataSource="@data" ShowGrandTotals="true" ShowSubTotals="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="Sold Amount"></PivotViewValue>
                </PivotViewValues>
                <PivotViewFormatSettings>
                    <PivotViewFormatSetting Name="Amount" Format="C"></PivotViewFormatSetting>
                </PivotViewFormatSettings>
            </PivotViewDataSourceSettings>
            <PivotViewEvents TValue="ProductDetails" RenameReport="renamereport" RemoveReport="removereport" SaveReport="savereport" LoadReport="loadreport" FetchReport="fetchreport" ></PivotViewEvents>
            <PivotViewGridSettings ColumnWidth="140"></PivotViewGridSettings>
    </EjsPivotView>

    @code{
        public List<ToolbarItems> toolbar = new List<ToolbarItems> {
            ToolbarItems.New,
            ToolbarItems.Load,
            ToolbarItems.Remove,
            ToolbarItems.Rename,
            ToolbarItems.SaveAs,
            ToolbarItems.Save,
            ToolbarItems.Grid,
            ToolbarItems.Chart,
            ToolbarItems.Export,
            ToolbarItems.SubTotal,
            ToolbarItems.GrandTotal,
            ToolbarItems.ConditionalFormatting,
            ToolbarItems.FieldList
        };
        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 List<string> report = new List<string>();
        public List<string> reportName = new List<string>();
        //to save report
        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);
            }

        }
        //fetch reports
        public void fetchreport(FetchReportArgs args)
        {
            args.ReportName = this.reportName.ToArray();

        }
        //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.LoadPersistData(this.report[j]);
        }
        //to delete a report
        public void removereport(RemoveReportArgs args)
        {
            var i = 0;
            for( i=0;i<this.reportName.Count; i++)
            {
                if(this.reportName[i] == args.ReportName)
                {
                    this.reportName.RemoveAt(i);
                    this.report.RemoveAt(i);
                }
            }
        }
        // to rename a report
        public void renamereport(RenameReportArgs args)
        {
            var i = 0;
            for( i=0;i<=(this.reportName.Count - 1); i++)
            {
                if(this.reportName[i] == args.ReportName)
                {
                    this.reportName.RemoveAt(i);
                    this.reportName.Add(args.Rename);
                }
            }
        }
    }

output