Search results

Sorting in ASP.NET MVC Pivot Grid control

14 Oct 2021 / 1 minute to read

Sorting allows you to order the field header in rows and columns either in ascending or descending. Sorting can been enabled by setting the enableSorting property to true.

By default, field headers in rows and columns are in ascending order.

Sorting through UI

Sorting can also be performed through UI option available in grouping bar and field list at run time.

Sorting through code

Sorting can be configured using the sortSettings option through code behind, during initial rendering. The settings required to sort are:

  • name: It allows to set the field name.
  • order: It allows to set the sort direction of the respective field.
Copied to clipboard
@using Syncfusion.EJ2.PivotView

@Html.EJS().PivotView("PivotGrid").Height(300).DataSource(dataSource => dataSource.Data((IEnumerable<object>)ViewBag.Data).ExpandAll(false).EnableSorting(true)
.SortSettings(sortsettings =>
}).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();
Copied to clipboard
public ActionResult Index()
    var data = GetPivotData(); = data;
    return View();

See Also