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
Feb/21/2015
11:17 PM
Germany
179
5,343.88
4,064.33
1
Mar/09/2015
11:18 AM
Germany
558
8,035.11
1,384.80
2
Jun/19/2015
2:17 PM
Germany
86
5,610.17
4,069.10
3
Jul/20/2015
6:24 AM
UK
704
3,179.86
4,927.53
4
May/03/2015
3:27 PM
Italy
571
405.60
449.91
5
Dec/18/2015
11:29 AM
Germany
596
80.78
3,346.61
6
Jul/24/2015
11:12 PM
Italy
118
8,973.21
3,881.66
7
Sep/14/2015
8:20 AM
Greece
548
9,131.06
4,700.80
8
Feb/04/2015
8:18 AM
UK
456
6,718.27
1,815.35
9
Mar/23/2015
4:37 AM
Greece
378
1,400.87
836.99
10
Jan/03/2015
5:43 PM
Japan
231
7,891.46
3,253.46
11
Oct/21/2015
11:25 PM
UK
34
9,388.05
1,661.47
12
Feb/18/2015
1:32 PM
UK
993
6,322.25
3,189.52
13
Nov/02/2015
12:05 PM
Greece
192
2,973.65
3,013.00
14
Apr/14/2015
6:18 PM
Japan
727
2,846.39
1,040.04

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)
}