ComponentOne
Web API Explorer ASP.NET Web API Explorer

Wijmo5FlexGrid

Grouping

This sample demonstrates how to export and import a grouping wijmo5 flexgrid to excel file.

Features

Id
Date
Time
Country
Downloads
Sales
Expenses
Checked
0
Jan/03/2015
10:31 AM
Japan
871
7,117.23
4,641.88
1
Aug/17/2015
2:14 AM
UK
616
4,811.98
1,504.57
2
Mar/12/2015
8:56 PM
UK
63
342.68
1,374.80
3
Feb/06/2015
4:38 PM
Italy
232
9,223.80
2,532.06
4
Sep/22/2015
9:00 AM
Italy
434
6,367.74
4,227.06
5
Nov/18/2015
7:32 PM
Japan
15
2,320.27
1,818.94
6
Oct/18/2015
1:25 PM
Germany
293
6,216.92
3,702.62
7
Nov/23/2015
10:31 PM
UK
331
9,276.48
1,698.31
8
Nov/15/2015
11:41 AM
Germany
502
2,852.19
4,560.46
9
Feb/15/2015
12:41 PM
Japan
186
8,978.48
1,847.26
10
Jun/19/2015
7:44 AM
Italy
264
6,574.77
1,497.02
11
Mar/01/2015
9:03 AM
UK
121
8,604.63
4,469.90
12
Nov/19/2015
12:59 AM
Germany
829
7,803.16
2,437.06
13
Jan/25/2015
12:40 AM
US
486
8,604.24
1,437.45
14
Mar/16/2015
4:53 AM
Japan
166
3,920.68
2,242.66

Settings


Export
Export Name :

Description

This sample demonstrates how to export and import a grouping wijmo5 flexgrid to excel file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using Microsoft.AspNetCore.Mvc;
using WebApiExplorer.Models;
  
namespace WebApiExplorer.Controllers.Wijmo5FlexGrid
{
    public partial class Wijmo5FlexGridController : Controller
    {
        private readonly GridExportImportOptions _flexGridGroupingModel = new GridExportImportOptions
        {
            NeedExport = true,
            NeedImport = false,
            IncludeColumnHeaders = true
        };
        public IActionResult Grouping()
        {
            ViewBag.Options = _flexGridGroupingModel;
            return View();
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
@{
    GridExportImportOptions optionsModel = ViewBag.Options;
    ViewBag.DemoSettings = true;
}
  
<div id="@(optionsModel.ControlId)" style="height:300px"></div>
<select id="gMenu">
    <option value="" selected>@Html.Raw(Wijmo5FlexGrid.Grouping_Groupint_None)</option>
    <option value="country">Country</option>
    <option value="sales">Sales</option>
    <option value="date">Date</option>
    <option value="country,date">Country and Date</option>
    <option value="country,sales">Country and Sales</option>
    <option value="country,date,sales">Country, Date, and Sales</option>
</select>
@section Settings{
    @Html.Partial("_FlexGridOptions", optionsModel)
}
<script>
    var grid = new wijmo.grid.FlexGrid('#@(optionsModel.ControlId)'), filter, menu = new wijmo.input.Menu('#gMenu'), cv;
    initializeFlexGrid(grid);
    cv = grid.collectionView;
    updateMenuHeader();
    menu.itemClicked.addHandler(function (sender) {
        var groupBy = sender.selectedValue;
        cv.groupDescriptions.clear();
        if (groupBy) {
            var groupNames = groupBy.split(',');
            for (var i = 0; i < groupNames.length; i++) {
                var groupName = groupNames[i];
                if (groupName == 'date') { // group dates by year
                    var groupDesc = new wijmo.collections.PropertyGroupDescription(groupName, function (item, prop) {
                        return item.date.getFullYear();
                    });
                    cv.groupDescriptions.push(groupDesc);
                }
                else if (groupName == 'sales') { // group amounts in ranges
                    var groupDesc = new wijmo.collections.PropertyGroupDescription(groupName, function (item, prop) {
                        return item.amount >= 5000 ? '> 5,000' : item.amount >= 500 ? '500 to 5,000' : '< 500';
                    });
                    cv.groupDescriptions.push(groupDesc);
                }
                else { // group everything else by value
                    var groupDesc = new wijmo.collections.PropertyGroupDescription(groupName);
                    cv.groupDescriptions.push(groupDesc);
                }
            }
        }
        updateMenuHeader();
    });
  
    function updateMenuHeader() {
        menu.header = '<b>@(Wijmo5FlexGrid.Grouping_GroupBy)</b> ' + menu.text;
    }
</script>
@section Description{
    @Html.Raw(Wijmo5FlexGrid.Grouping_Text0)
}