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/22/2015
4:12 AM
Japan
546
61.08
2,416.94
1
Jul/15/2015
7:14 PM
Italy
384
7,079.68
785.62
2
Aug/06/2015
6:28 AM
Italy
101
759.92
3,228.04
3
Oct/04/2015
8:55 PM
Japan
759
1,466.49
792.95
4
Jul/08/2015
8:01 PM
Greece
762
5,476.17
942.40
5
May/09/2015
10:16 PM
Italy
514
6,963.63
1,352.86
6
Sep/12/2015
4:17 AM
Italy
608
4,319.61
4,680.56
7
May/05/2015
6:27 AM
Germany
263
9,034.98
815.34
8
Jul/08/2015
6:41 AM
Germany
831
1,101.32
4,386.68
9
Sep/17/2015
8:20 PM
US
3
6,957.91
330.98
10
Sep/12/2015
11:35 AM
Greece
712
6,873.19
985.59
11
Oct/09/2015
4:56 PM
US
810
449.57
3,458.18
12
May/11/2015
12:29 PM
Greece
567
5,634.31
4,127.86
13
Nov/24/2015
12:33 AM
US
389
4,546.94
415.64
14
Sep/13/2015
1:40 AM
Germany
676
2,195.41
1,177.54

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