ComponentOne
Web API Explorer ASP.NET Web API Explorer

Wijmo5FlexGrid

Conditional Styling

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

Features

Id
Date
Country
Sales
0
Jun/13/2015
Japan
2,691.29
1
Jan/08/2015
Greece
9,316.85
2
Dec/02/2015
Italy
3,243.81
3
Jul/07/2015
UK
9,141.21
4
Apr/11/2015
UK
2,321.05
5
Dec/09/2015
Japan
9,402.30
6
Sep/25/2015
Germany
4,002.22
7
Apr/22/2015
Italy
4,626.16
8
Nov/12/2015
Germany
3,949.65
9
May/04/2015
Germany
607.74
10
Nov/20/2015
Japan
6,903.23
11
Feb/13/2015
Germany
4,488.60
12
Oct/05/2015
Greece
1,501.72
13
Jun/24/2015
Greece
5,259.91
14
Feb/16/2015
UK
7,837.75

Settings


Export
Export Name :

Description

This sample demonstrates how to export a wijmo5 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
using Microsoft.AspNetCore.Mvc;
using WebApiExplorer.Models;
  
namespace WebApiExplorer.Controllers
{
    public partial class Wijmo5FlexGridController : Controller
    {
        private readonly GridExportImportOptions _flexGridConditionalStylingModel = new GridExportImportOptions
        {
            NeedExport = true,
            NeedImport = false,
            IncludeColumnHeaders = true
        };
  
        public IActionResult ConditionalStyling()
        {
            ViewBag.Options = _flexGridConditionalStylingModel;
            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
@{
    GridExportImportOptions optionsModel = ViewBag.Options;
    ViewBag.DemoSettings = true;
}
  
<div id="@(optionsModel.ControlId)" style="height:300px"></div>
  
@section Settings{
    @Html.Partial("_FlexGridOptions", optionsModel)
}
<script>
    var grid = new wijmo.grid.FlexGrid('#@(optionsModel.ControlId)');
    grid.initialize({
        autoGenerateColumns: false,
        columns: [
            { header: 'Id', binding: 'id' },
            { header: 'Date', binding: 'date', format: 'MMM/dd/yyyy' },
            { header: 'Country', binding: 'country' },
            { header: 'Sales', binding: 'sales', width: '*' }
        ],
        itemsSource: getGridData(100),
        allowResizing: 'None'
    });
    grid.itemFormatter = function (panel, r, c, cell) {
  
        // validate CellType and if correct column
        if (wijmo.grid.CellType.Cell === panel.cellType &&
            'sales' === 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 < 3000 ? 'red' : amount < 6000 ? 'black' : 'green';
    }
</script>
@section Description{
    @Html.Raw(Wijmo5FlexGrid.ConditionalStyling_Text0)
}