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
May/04/2015
3:03 PM
Greece
811
8,967.83
951.88
1
Aug/11/2015
10:18 AM
UK
714
7,864.92
1,446.54
2
Jun/08/2015
12:54 PM
Germany
55
3,223.00
3,431.20
3
Apr/13/2015
1:03 PM
Japan
512
1,605.27
2,878.80
4
Jan/16/2015
11:35 AM
Italy
993
4,824.78
2,598.64
5
Jul/11/2015
8:29 AM
Japan
85
7,359.99
2,147.84
6
May/16/2015
10:34 AM
Greece
17
1,846.48
1,643.94
7
Jan/20/2015
9:11 PM
Japan
499
6,554.78
4,958.30
8
Apr/05/2015
6:38 AM
UK
954
1,815.37
2,263.85
9
Feb/13/2015
11:48 PM
Japan
255
283.78
2,089.41
10
Oct/24/2015
10:16 AM
Italy
274
9,691.62
2,495.38
11
Dec/14/2015
6:16 PM
Italy
978
4,272.98
4,367.87
12
Aug/23/2015
7:01 PM
US
207
7,866.80
644.59
13
Jan/05/2015
7:12 PM
Germany
210
9,060.40
2,765.00
14
Jul/15/2015
9:37 AM
US
178
2,965.84
1,088.56

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
21
22
23
24
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApiExplorer.Models;
 
namespace WebApiExplorer.Controllers
{
    public partial class Wijmo5FlexGridController : Controller
    {
        private readonly GridExportImportOptions _flexGridGroupingModel = new GridExportImportOptions
        {
            NeedExport = true,
            NeedImport = false,
            IncludeColumnHeaders = true
        };
        public ActionResult 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
59
@using WebApiExplorer.Models
@{
    GridExportImportOptions optionsModel = ViewBag.Options;
    ViewBag.DemoSettings = true;
}
 
<div id="@(optionsModel.ControlId)" style="height:300px"></div>
<select id="gMenu">
    <option value="" selected>@Html.Raw(Resources.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>@(Resources.Wijmo5FlexGrid.Grouping_GroupBy)</b> ' + menu.text;
    }
</script>
@section Description{
    @Html.Raw(Resources.Wijmo5FlexGrid.Grouping_Text0)
}