Search results

Sorting

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.
razor
Sorting.cs
@using Syncfusion.EJ2.PivotView

@Html.EJS().PivotView("PivotGrid").Height(300).DataSource(dataSource => dataSource.Data((IEnumerable<object>)ViewBag.Data).ExpandAll(false).EnableSorting(true)
.SortSettings(sortsettings =>
{
    sortsettings.Name("Country").Order(Sorting.Descending).Add();
}).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();
})).Render()
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.data = data;
    return View();
}