ComponentOne
Web API Explorer ASP.NET Web API Explorer

MVCFlexGrid

Conditional Styling

This sample demonstrates how to export a mvc flexgrid with format cells to excel file.

Features

ID
Country
Product
Amount
1
German
Gadget
$581.61
2
Canada
Gadget
$4,919.02
3
Japan
Gadget
$2,159.73
4
German
Gadget
$1,248.66
5
German
Gadget
$4,051.76
6
Canada
Gadget
($3,131.28)
7
China
Widget
$698.62
8
US
Widget
$3,464.15
9
Korea
Gadget
($2,363.16)
10
US
Widget
($2,836.94)
11
France
Widget
$877.93
12
Korea
Widget
($3,788.14)
13
German
Gadget
($2,446.92)
14
German
Widget
($4,374.97)
15
Japan
Gadget
$1,089.32
16
China
Gadget
$1,341.85
17
US
Widget
$3,596.33
18
China
Widget
$3,232.11
19
France
Gadget
($2,008.99)
20
France
Gadget
$2,568.01
21
UK
Widget
($3,476.95)
22
UK
Widget
$2,290.56
23
Japan
Gadget
($4,146.76)
24
Canada
Gadget
$4,917.55
25
Korea
Gadget
$3,824.28
26
Japan
Gadget
($4,257.83)
27
Italy
Gadget
$1,095.08
28
German
Gadget
$1,853.66
29
Italy
Widget
$3,708.86
30
Canada
Gadget
($3,447.73)
31
German
Gadget
($165.64)
32
China
Widget
$160.62
33
Korea
Widget
($2,575.30)
34
Italy
Widget
$3,288.12
35
Korea
Gadget
($4,563.28)
36
Canada
Widget
($4,839.71)
37
US
Gadget
$544.13
38
Canada
Widget
$538.45
39
Japan
Gadget
$1,493.10
40
US
Widget
($2,838.54)
41
UK
Gadget
($3,175.21)
42
France
Widget
$22.88
43
Korea
Widget
($4,129.88)
44
Korea
Gadget
$2,170.82
45
Korea
Gadget
($3,000.98)
46
US
Gadget
$3,374.49
47
Canada
Widget
($2,103.52)
48
German
Widget
($2,077.64)
49
France
Gadget
($748.11)
50
German
Widget
$678.23
51
Italy
Gadget
$4,420.76
52
China
Widget
($4,161.96)
53
China
Gadget
($4,266.09)
54
Korea
Gadget
($3,422.65)
55
China
Gadget
($185.37)
56
US
Widget
($4,675.00)
57
Canada
Gadget
($1,746.26)
58
German
Widget
($3,518.88)
59
Canada
Widget
($228.15)
60
Italy
Widget
($839.21)
61
US
Widget
$2,042.44
62
US
Gadget
$4,568.40
63
Korea
Widget
$595.84
64
Canada
Gadget
($2,520.97)
65
Korea
Gadget
$3,017.71
66
Korea
Widget
($3,412.10)
67
Korea
Gadget
($3,256.14)
68
China
Gadget
$4,334.98
69
China
Widget
($989.05)
70
US
Widget
$2,673.11
71
Japan
Gadget
$4,676.20
72
German
Widget
($4,427.85)
73
Japan
Gadget
($4,916.10)
74
China
Widget
($1,940.69)
75
German
Widget
($862.78)
76
Canada
Gadget
$2,015.45
77
Japan
Gadget
$4,585.00
78
US
Widget
$1,986.58
79
US
Widget
($3,469.64)
80
German
Gadget
$2,342.70
81
UK
Gadget
$4,479.22
82
US
Gadget
$2,869.30
83
US
Gadget
($2,190.02)
84
Italy
Widget
$322.50
85
France
Widget
($1,479.40)
86
Italy
Widget
$3,689.48
87
Canada
Widget
($1,241.87)
88
Japan
Gadget
$4,009.94
89
Japan
Gadget
$2,323.39
90
Italy
Gadget
($1,227.88)
91
German
Widget
($456.57)
92
Italy
Widget
($992.57)
93
Canada
Gadget
($4,707.05)
94
US
Widget
$2,301.03
95
German
Gadget
($1,062.14)
96
France
Widget
($587.13)
97
US
Gadget
$2,518.17
98
Japan
Widget
$4,900.51
99
Japan
Gadget
$2,920.44
100
France
Widget
$568.63

Settings


Export
Export Name :

Description

This sample demonstrates how to export a mvc flexgrid with format cells 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
25
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 MVCFlexGridController : Controller
    {
        private readonly GridExportImportOptions _flexGridConditionalStylingModel = new GridExportImportOptions
        {
            NeedExport = true,
            NeedImport = false,
            IncludeColumnHeaders = true
        };
 
        public ActionResult ConditionalStyling()
        {
            ViewBag.Options = _flexGridConditionalStylingModel;
            return View(Sale.GetData(100));
        }
    }
}
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
@using WebApiExplorer.Models
@using C1.Web.Mvc.Grid
@model IEnumerable<Sale>
@{
    ClientSettingsModel demoSettingsModel = ViewBag.DemoSettingsModel;
    GridExportImportOptions optionsModel = ViewBag.Options;
    ViewBag.DemoSettings = true;
}
 
<script>
    function itemFormatter(panel, r, c, cell) {
 
        // validate CellType and if correct column
        if (wijmo.grid.CellType.Cell === panel.cellType &&
            'Amount' === panel.columns[c].binding) {
 
            // get the cell's data
            var cellData = panel.getCellData(r, c);
 
            // set cell's foreground color
            cell.style.color = getAmountColor(cellData);
        }
    }
 
    // get the color used to display an amount
    function getAmountColor(amount) {
        return amount < 1500 ? 'red' : amount < 3000 ? 'black' : 'green';
    }
</script>
 
@(Html.C1().FlexGrid<Sale>().Id(optionsModel.ControlId)
    .AutoGenerateColumns(false)
    .IsReadOnly(true)
    .Bind(Model)
    .CssClass("grid")
    .AllowResizing(AllowResizing.None)
    .ItemFormatter("itemFormatter")
    .Columns(columns =>
    {
        columns.Add(column => column.Binding("ID"));
        columns.Add(column => column.Binding("Country"));
        columns.Add(column => column.Binding("Product"));
        columns.Add(column => column.Binding("Amount").Format("c").Width("*").Align("center"));
    })
)
 
@section Settings{
    @Html.Partial("_FlexGridOptions", optionsModel)
}
 
@section Description{
    @Html.Raw(Resources.MVCFlexGrid.ConditionalStyling_Text0)
}