Search results

Value sorting

Value sorting allows you to sort individual column based on it’s values either in ascending or descending order. It can been enabled by setting the enableValueSorting property to true. You can sort the column values by clicking the column header.

Value sorting can be configured using the valueSortSettings option through code behind. The settings required to sort value fields at initial rendering are:

  • headerText: It allows to set the column header names with delimiters, that is used for value sorting.
  • headerDelimiter: It allows to set the delimiters string to separate the given header text.
  • sortOrder: It allows to set the sort direction of the value field.
razor
ValueSorting.cs
@using Syncfusion.EJ2.PivotView

@Html.EJS().PivotView("PivotGrid").Height(300).DataSource(dataSource => dataSource.Data((IEnumerable<object>)ViewBag.Data).ExpandAll(false)
.ValueSortSettings(new PivotViewValueSortSettings {
    HeaderText = "FY 2015##Sold Amount",
    HeaderDelimiter = "##",
    SortOrder = Sorting.Descending })
.Rows(rows =>
{
    rows.Name("Country").Add(); rows.Name("Products").Add();
}).Columns(columns =>
{
    columns.Name("Year").Caption("Production Year").Add(); columns.Name("Quarter").Add();
}).Values(values =>
{
    values.Name("Sold").Caption("Units Sold").Add(); values.Name("Amount").Caption("Sold Amount").Add();
})).EnableValueSorting(true).Render()
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.data = data;
    return View();
}