FlexGrid
Sorting
In this sample, you can sort the collection based on the corresponding field value chosen in the first list.
Features
ID
Start
End
Country
Product
Color
Amount
Amount2
Discount
Active
1
1/25/2025
1/25/2025
German
Gadget
Green
$581.61
$1,030.17
14%
2
2/25/2025
2/25/2025
Italy
Gadget
Green
($4,673.75)
$3,499.71
13%
3
3/25/2025
3/25/2025
China
Gadget
Black
($2,265.49)
$4,535.49
20%
4
4/25/2025
4/25/2025
France
Widget
Green
$3,964.40
$432.90
21%
5
5/25/2025
5/25/2025
UK
Widget
Red
($1,744.99)
$3,355.18
12%
6
6/25/2025
6/25/2025
France
Gadget
Red
$4,276.37
$1,106.71
23%
7
7/25/2025
7/25/2025
US
Widget
Green
($4,376.92)
$1,408.24
18%
8
8/25/2025
8/25/2025
Japan
Gadget
Black
$1,996.52
$3,077.04
21%
9
9/25/2025
9/25/2025
Korea
Widget
Red
($3,442.35)
$4,068.26
16%
10
10/25/2025
10/25/2025
US
Widget
Green
($2,973.96)
$4,568.15
1%
11
11/25/2025
11/25/2025
Canada
Widget
Green
($3,217.79)
$4,414.46
14%
12
12/25/2025
12/25/2025
UK
Gadget
Red
$1,556.19
$1,705.14
1%
13
1/25/2025
1/25/2025
Canada
Gadget
Red
($4,981.75)
$4,917.13
24%
14
2/25/2025
2/25/2025
China
Gadget
Green
($397.56)
$1,702.41
19%
15
3/25/2025
3/25/2025
Italy
Widget
Green
$199.60
$4,148.18
14%
16
4/25/2025
4/25/2025
China
Gadget
Green
($176.56)
$506.04
11%
17
5/25/2025
5/25/2025
Canada
Widget
Black
($542.28)
$1,471.61
21%
18
6/25/2025
6/25/2025
Japan
Gadget
Red
$4,319.97
$4,562.80
7%
19
7/25/2025
7/25/2025
France
Gadget
Green
($1,397.67)
$3,784.00
20%
20
8/25/2025
8/25/2025
UK
Widget
Black
($3,476.95)
$4,926.25
1%
21
9/25/2025
9/25/2025
UK
Gadget
Red
$3,295.03
$1,143.47
10%
22
10/25/2025
10/25/2025
China
Widget
Red
($4,598.11)
$3,889.99
9%
23
11/25/2025
11/25/2025
Korea
Widget
Red
($3,396.86)
$4,829.86
11%
24
12/25/2025
12/25/2025
German
Widget
Green
$4,399.82
$2,594.90
5%
25
1/25/2025
1/25/2025
Korea
Gadget
Red
$3,235.00
$1,183.91
21%
26
2/25/2025
2/25/2025
Korea
Widget
Red
$341.60
$1,285.88
0%
27
3/25/2025
3/25/2025
France
Widget
Red
$1,561.78
$4,661.58
8%
28
4/25/2025
4/25/2025
German
Widget
Red
($191.55)
$812.79
1%
29
5/25/2025
5/25/2025
Korea
Widget
Black
$1,516.57
$466.65
16%
30
6/25/2025
6/25/2025
Italy
Gadget
Red
$4,470.85
$527.11
23%
31
7/25/2025
7/25/2025
Canada
Widget
Black
$4,796.84
$1,327.69
10%
32
8/25/2025
8/25/2025
France
Gadget
Black
$2,871.26
$3,139.54
9%
33
9/25/2025
9/25/2025
US
Gadget
Green
($3,744.20)
$4,940.47
6%
34
10/25/2025
10/25/2025
Japan
Widget
White
($2,588.21)
$914.61
7%
35
11/25/2025
11/25/2025
Japan
Widget
Black
($3,709.87)
$379.20
18%
36
12/25/2025
12/25/2025
German
Gadget
Green
($2,500.33)
$1,337.27
18%
37
1/25/2025
1/25/2025
China
Gadget
White
$1,169.17
$2,552.76
16%
38
2/25/2025
2/25/2025
UK
Widget
White
($3,578.79)
$1,080.73
23%
39
3/25/2025
3/25/2025
UK
Gadget
Black
($3,175.21)
$1,174.79
18%
40
4/25/2025
4/25/2025
US
Widget
Red
($2,410.67)
$3,407.91
11%
41
5/25/2025
5/25/2025
UK
Widget
Black
$1,645.36
$2,607.51
12%
42
6/25/2025
6/25/2025
German
Widget
Red
($38.23)
$4,135.44
12%
43
7/25/2025
7/25/2025
China
Widget
White
($2,409.07)
$2,411.30
22%
44
8/25/2025
8/25/2025
Korea
Gadget
Black
($1,396.05)
$115.18
0%
45
9/25/2025
9/25/2025
US
Widget
White
($78.75)
$3,762.99
18%
46
10/25/2025
10/25/2025
Japan
Gadget
White
($3,179.15)
$97.09
17%
47
11/25/2025
11/25/2025
Japan
Widget
Green
($1,872.55)
$342.34
19%
48
12/25/2025
12/25/2025
US
Widget
White
$2,186.94
$743.95
5%
49
1/25/2025
1/25/2025
Canada
Widget
White
($4,924.10)
$1,601.10
14%
50
2/25/2025
2/25/2025
US
Widget
Green
($3,540.61)
$4,553.11
9%
ID
Start
End
Country
Product
Color
Amount
Amount2
Discount
Active
0
Settings
Sorting Field :Description
In this sample, you can sort the collection based on the corresponding field value chosen in the first list. You can also specify the sorting order in the second list.
Use the SortingType property to change this behavior so users can sort none/single/multiple columns at a time.
Use the SortingType property to change this behavior so users can sort none/single/multiple columns at a time.
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 | using MvcExplorer.Models; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcExplorer.Controllers { public partial class FlexGridController : Controller { private readonly ControlOptions _sortingDataModel = new ControlOptions { Options = new OptionDictionary { { "Sorting type" , new OptionItem {Values = new List< string > { "None" , "SingleColumn" , "MultiColumn" }, CurrentValue = "SingleColumn" }} } }; public ActionResult Sorting(FormCollection collection) { _sortingDataModel.LoadPostData(collection); ViewBag.DemoOptions = _sortingDataModel; return View(Sale.GetData(50)); } } } |
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 60 61 62 63 64 65 66 67 | @using C1.Web.Mvc.Grid @model IEnumerable< Sale > @ { var fields = new [] { "ID" , "Start" , "End" , "Country" , "Product" , "Color" , "Amount" , "Amount2" , "Discount" , "Active" }; var orders = new [] { "Ascending" , "Descending" }; ControlOptions optionsModel = ViewBag.DemoOptions; ViewBag.DemoSettings = true ; ViewBag.SettingsByMenu = false ; } @ (Html.C1().FlexGrid< Sale >() .AutoGenerateColumns( false ) .Id( "flexgrid" ) .CssClass( "grid" ) .IsReadOnly( true ) .Bind(Model) .OrderBy( "ID" ) .SortingType((AllowSorting)Enum.Parse( typeof (AllowSorting), optionsModel.Options[ "Sorting type" ].CurrentValue)) .Columns(bl => { bl.Add(cb => cb.Binding( "ID" )); bl.Add(cb => cb.Binding( "Start" )); bl.Add(cb => cb.Binding( "End" )); bl.Add(cb => cb.Binding( "Country" )); bl.Add(cb => cb.Binding( "Product" )); bl.Add(cb => cb.Binding( "Color" )); bl.Add(cb => cb.Binding( "Amount" ).Format( "c" )); bl.Add(cb => cb.Binding( "Amount2" ).Format( "c" )); bl.Add(cb => cb.Binding( "Discount" ).Format( "p0" )); bl.Add(cb => cb.Binding( "Active" )); }) ) @section Scripts{ <script> var field = "ID" , order = "Ascending" ; function sortGrid(combo) { var flexGrid, ascending, sd; if (combo.hostElement.id === "sortingfield" ) field = combo.selectedValue; if (combo.hostElement.id === "sortingorder" ) order = combo.selectedValue; if (!field || !order) { return ; } flexGrid = wijmo.Control.getControl( "#flexgrid" ); ascending = order === "Ascending" ; sd = flexGrid.collectionView.sortDescriptions; sdNew = new wijmo.collections.SortDescription(field, ascending); // remove any old sort descriptors and add the new one sd.splice(0, sd.length, sdNew); } </script> } @section Settings { @Html .Raw(Resources.FlexGrid.Sorting_SortingField) : @ (Html.C1().ComboBox().Id( "sortingfield" ).Bind(fields).SelectedIndex(0).IsEditable( false ).OnClientSelectedIndexChanged( "sortGrid" )) @Html .Raw(Resources.FlexGrid.Sorting_SortingOrder) : @ (Html.C1().ComboBox().Id( "sortingorder" ).Bind(orders).SelectedIndex(0).IsEditable( false ).OnClientSelectedIndexChanged( "sortGrid" )) @Html .Partial( "_OptionsMenu" , optionsModel) } @section Description{ @Html .Raw(Resources.FlexGrid.Sorting_Text0)< br /> @Html .Raw(Resources.FlexGrid.SortingType_Text0) } |