diff --git a/blazor/pivot-table/excel-export.md b/blazor/pivot-table/excel-export.md index 83298f4f54..1a624f1af2 100644 --- a/blazor/pivot-table/excel-export.md +++ b/blazor/pivot-table/excel-export.md @@ -9,7 +9,14 @@ documentation: ug # Excel export in Blazor Pivot Table component -The Excel export allows Pivot Table data to be exported as Excel document. To enable Excel export in the pivot table, set the [AllowExcelExport](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_AllowExcelExport) property in [SfPivotView](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html) class to **true**. Once the API is set, user needs to call the [ExportToExcelAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_ExcelExport_System_Object_System_Nullable_System_Boolean__System_Object_System_Nullable_System_Boolean__) method for exporting on external button click. +The Excel export allows Pivot Table data to be exported as Excel document. To enable Excel export in the pivot table, set the [AllowExcelExport](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_AllowExcelExport) property in [SfPivotView](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html) class to **true**. Once the API is set, user needs to call the [ExportToExcelAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_ExcelExport_System_Object_System_Nullable_System_Boolean__System_Object_System_Nullable_System_Boolean__) method for exporting on external button click. + +This method accepts a boolean parameter, **"asMemoryStream"**, which determines the export behavior: + +* **false:** Downloads the Excel file directly. +* **true:** Returns the file as a memory stream for custom processing, storage, or manipulation. + +In this example, false is used to initiate a direct download. N> The pivot table component can be exported to Excel format using options available in the toolbar. For more details [refer](./tool-bar) here. @@ -43,12 +50,12 @@ N> The pivot table component can be exported to Excel format using options avail public List Data { get; set; } protected override void OnInitialized() { - this.data = ProductDetails.GetProductData().ToList(); + 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 void OnExcelExport(Microsoft.AspNetCore.Components.Web.MouseEventArgs args){ - this.pivot.ExportToExcelAsync(); + this.pivot.ExportToExcelAsync(false); } } ``` @@ -91,7 +98,7 @@ N> By default, material theme will be applied to the pivot table during Excel ex public List Data { get; set; } protected override void OnInitialized() { - this.data = ProductDetails.GetProductData().ToList(); + 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. } @@ -223,7 +230,7 @@ The Excel export provides an option to change file name of the document before e public List Data { get; set; } protected override void OnInitialized() { - this.data = ProductDetails.GetProductData().ToList(); + 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. } @@ -246,7 +253,14 @@ By default, Microsoft Excel supports only 1,048,576 records in an Excel sheet. H ## CSV Export -The Excel export allows pivot table data to be exported in **CSV** file format as well. To enable CSV export in the pivot table, set the [AllowExcelExport](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_AllowExcelExport) property in [SfPivotView](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html) class as **true**. Once the API is set, user needs to call the [ExportToCsvAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_CsvExport_System_Object_System_Nullable_System_Boolean__System_Object_System_Nullable_System_Boolean__) method for exporting on external button click. +The Excel export allows pivot table data to be exported in **CSV** file format as well. To enable CSV export in the pivot table, set the [AllowExcelExport](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_AllowExcelExport) property in [SfPivotView](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html) class as **true**. Once the API is set, user needs to call the [ExportToCsvAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_CsvExport_System_Object_System_Nullable_System_Boolean__System_Object_System_Nullable_System_Boolean__) method for exporting on external button click. + +This method accepts a boolean parameter, **"asMemoryStream"**, which determines the export behavior: + +* **false:** Downloads the Excel file directly. +* **true:** Returns the file as a memory stream for custom processing, storage, or manipulation. + +In this example, false is used to initiate a direct download. N> The pivot table component can be exported to CSV format using options available in the toolbar. For more details [refer](./tool-bar) here. @@ -278,14 +292,14 @@ N> The pivot table component can be exported to CSV format using options availab @code{ SfPivotView pivot; public List Data { get; set; } - protected override void OnInitialized(Microsoft.AspNetCore.Components.Web.MouseEventArgs args) + protected override void OnInitialized() { - this.data = ProductDetails.GetProductData().ToList(); + 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 void OnCsvExport() { - this.pivot.ExportToCsvAsync(); + this.pivot.ExportToCsvAsync(false); } } @@ -332,6 +346,73 @@ When the [EnableVirtualization](https://help.syncfusion.com/cr/blazor/Syncfusion }; } ``` + +## Saving Excel document to stream + +Rather than exporting the Pivot Table as a downloadable file, the user can save the Excel document as a memory stream. This is achieved by setting the **asMemoryStream** parameter to **true** in the [ExportToExcelAsync](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.SfPivotView-1.html#Syncfusion_Blazor_PivotView_SfPivotView_1_ExcelExport_System_Object_System_Nullable_System_Boolean__System_Object_System_Nullable_System_Boolean__) method. The resulting memory stream can then be further processed and customized by the user before being exported as a document. + +N> This option is only available if virtualization is enabled in the pivot table. + +```cshtml +@using Syncfusion.Blazor.PivotView +@using Syncfusion.Blazor.Buttons +@using Syncfusion.Blazor +@inject IJSRuntime JSRuntime + + + + + + + + + + + + + + + + + + + + + + + + +@code { + private SfPivotView pivot; + private List 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. + } + private async Task OnPdfExport(Microsoft.AspNetCore.Components.Web.MouseEventArgs args) + { + System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); + //Excel document as a memory stream by setting the first parameter as "true" in the "ExportToExcelAsync" method. + memoryStream = await this.pivot.ExportToExcelAsync(true); + // You can then process the memory stream based on your needs and save it as mentioned in the last statement. + ...... + ...... + ...... + await JSRuntime.InvokeVoidAsync("saveAsFile", new object[] { "default.xlsx", Convert.ToBase64String(memoryStream.ToArray()),true }); + } +} +``` + ## Events ### ExcelQueryCellInfo @@ -377,24 +458,24 @@ The event [ExcelQueryCellInfo](https://help.syncfusion.com/cr/blazor/Syncfusion. private SfPivotView pivot; public List Data { get; set; } - protected override void OnInitialized(Microsoft.AspNetCore.Components.Web.MouseEventArgs args) + protected override void OnInitialized() { - this.data = ProductDetails.GetProductData().ToList(); + 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 void OnExcelExport(Microsoft.AspNetCore.Components.Web.MouseEventArgs args) { - this.pivot.ExportToExcelAsync(); + this.pivot.ExportToExcelAsync(false); } // Triggers every time for row header and value cells during exporting. public void ExcelQueryEvent(ExcelQueryCellInfoEventArgs args) { - Matrix> pivotValues = Pivot?.PivotValues; + Matrix> pivotValues = pivot?.PivotValues; AxisSet cellInfo = null; - if (Pivot?.EnableVirtualization == true) + if (pivot?.EnableVirtualization == true) { if (pivotValues != null) { @@ -468,24 +549,24 @@ The event [ExcelHeaderQueryCellInfo](https://help.syncfusion.com/cr/blazor/Syncf private SfPivotView pivot; public List Data { get; set; } - protected override void OnInitialized(Microsoft.AspNetCore.Components.Web.MouseEventArgs args) + protected override void OnInitialized() { - this.data = ProductDetails.GetProductData().ToList(); + 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 void OnExcelExport(Microsoft.AspNetCore.Components.Web.MouseEventArgs args) { - this.pivot.ExportToExcelAsync(); + this.pivot.ExportToExcelAsync(false); } // Triggers every time for column header cells during exporting public void ExcelHeaderEvent(ExcelHeaderQueryCellInfoEventArgs args) { - Matrix> pivotValues = Pivot?.PivotValues; + Matrix> pivotValues = pivot?.PivotValues; AxisSet cellInfo = null; - if (Pivot?.EnableVirtualization == true) + if (pivot?.EnableVirtualization == true) { if (pivotValues != null) { diff --git a/blazor/pivot-table/sorting.md b/blazor/pivot-table/sorting.md index 682a5f96a7..c61aafd56d 100644 --- a/blazor/pivot-table/sorting.md +++ b/blazor/pivot-table/sorting.md @@ -163,6 +163,53 @@ N> Value fields are set to the column axis by default. In such cases, the value ![Value Sorting in Blazor PivotTable](images/blazor-pivottable-value-sorting.png) +### Multiple Axis Sorting + +Users can apply value sorting to both row and column axes simultaneously for more dynamic and precise data analysis. The following settings are used to configure sorting: + +* [ColumnHeaderText](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.PivotViewValueSortSettings.html#Syncfusion_Blazor_PivotView_PivotViewValueSortSettings_ColumnHeaderText): Specifies the column header hierarchy for value sorting. Header levels are defined from Level 1 to N using a delimiter for clarity. +* [HeaderDelimiter](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.PivotViewValueSortSettings.html#Syncfusion_Blazor_PivotView_PivotViewValueSortSettings_HeaderDelimiter): It allows to set the delimiters string to separate the header text between levels. +* [ColumnSortOrder](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.PivotViewValueSortSettings.html#Syncfusion_Blazor_PivotView_PivotViewValueSortSettings_ColumnSortOrder): Sets the delimiter string used to separate levels in the column header text. +* [RowHeaderText](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.PivotViewValueSortSettings.html#Syncfusion_Blazor_PivotView_PivotViewValueSortSettings_RowHeaderText): Defines the specific row header for which the value sorting should be applied. +* [RowSortOrder](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.PivotView.PivotViewValueSortSettings.html#Syncfusion_Blazor_PivotView_PivotViewValueSortSettings_RowSortOrder): Determines the sorting direction for the specified row header. + +N> This feature is applicable only to relational data sources. + +```cshtml +@using Syncfusion.Blazor.PivotView + + +   +         +             +             +         +         +             +             +         +         + +             +         +         +             +         + +     + + +@code{ + public List 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. + } +} + +``` + ## Events ### OnActionBegin