How to apply value sorting in code behind without binding column fields
This article explains how to apply value sorting in code behind without binding column fields.
Apply value sorting in code behind without binding column fields
In the pivot table, if you don’t bind fields to the column axis and only have fields in the values axis, the pivot table will display only the grand total columns for the bound value fields. To sort these grand total columns, you can utilize the HeaderText property in the PivotViewValueSortSettings. This property allows you to set the header names with delimiters, which are used for value sorting.
Note: In order to apply value sorting, it is important to set the EnableValueSorting property to true.
Here is a code example that shows how to apply value sorting in code without binding column fields.
[Index.razor]
<SfPivotView EnableValueSorting=true>
<PivotViewDataSourceSettings>
<PivotViewValueSortSettings HeaderText="Grand Total##Sold Amount" HeaderDelimiter="##" SortOrder=Sorting.Descending></PivotViewValueSortSettings>
</PivotViewDataSourceSettings>
</SfPivotView>
In this example, the HeaderText property is set to Grand Total##Sold Amount(i.e., Grand Totals + HeaderDelimiter + value field name), where Grand Total is the header text for the grand total columns and Sold Amount is the name of the value field. The HeaderDelimiter is set to ## to distinguish between the grand total header and the value field name. Finally, we set SortOrder property to Sorting.Descending
to sort the values in descending order.
The following screenshot, which portrays the results of the code snippet mentioned above,
Screenshot
For a practical demonstration, refer to the sample of blazor playground
Conclusion:
I hope you enjoyed learning how to apply value sorting in code behind without binding column fields.
You can also refer to our Pivot Table feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our Pivot Table example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, support portal, or feedback portal. We are always happy to assist you!