Search results

Configure data grid options on editing mode in ASP.NET MVC Pivot Grid control

14 Oct 2021 / 1 minute to read

You can access the data grid options such as sort, group, filter on editing mode using the beginDrillThrough event in the pivot grid. The event occurs in every value cell on double click and provides the data grid information before display the drill through grid pop-up.

razor
CustomEditing.cs
Copied to clipboard
@Html.EJS().PivotView("PivotGrid").Width("100%").Height("300").DataSource(dataSource => dataSource.Data((IEnumerable<object>)ViewBag.Data).ExpandAll(false).EnableSorting(true)
    .FormatSettings(formatsettings => 
    { 
        formatsettings.Name("Amount").Format("C0").MaximumSignificantDigits(10).MinimumSignificantDigits(1).UseGrouping(true).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(); 
    })).EditSettings(new PivotViewCellEditSettings{AllowAdding=true;AllowDeleting=true;AllowEditing=true;Mode=EditMode.Normal}).beginDrillThrough("beginDrillThrough").Render()

    <script>
        function beginDrillThrough(args) {
            if (args.gridObj) {
                var gridObj = args.gridObj;
                gridObj.allowGrouping = true;
                gridObj.allowSorting = true;
                gridObj.allowFiltering = true;
                gridObj.filterSettings = { type: 'CheckBox' };
            }
        }
    </script>
Copied to clipboard
public ActionResult Index()
{
    var data = GetPivotData();
    ViewBag.data = data;
    return View();
}