Stable Sort
The CollectionView class has a "stableSort" property that allows you to keep the original sequence of items when sorting by any fields in the data objects.
For example, this sample creates a CollectionView based on a list of items sorted by Country and ID. If you sort the grid by any property (e.g. Active), items with the same sort property value will be sorted according to the original order (sorted by Country and ID):
Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
1
Germany
Computers
111,632
20,603.32
27,944.24
7
Germany
Stereos
169,610
99,190.22
1,631.26
13
Germany
Computers
191,491
50,512.92
35,798.63
19
Germany
Stereos
147,079
85,821.92
33,987.45
25
Germany
Computers
20,187
72,909.41
35,922.53
31
Germany
Stereos
132,678
33,258.90
14,336.12
37
Germany
Computers
21,394
60,987.02
47,652.14
43
Germany
Stereos
104,548
28,032.53
25,328.81
49
Germany
Computers
113,948
17,276.76
9,226.64
55
Germany
Stereos
128,504
57,539.34
27,643.09
61
Germany
Computers
40,520
91,362.93
1,478.85
67
Germany
Stereos
26,452
89,725.33
8,911.06
73
Germany
Computers
156,815
13,306.00
30,625.19
Id
Country
Product
Active
Downloads
Sales
Expenses
Overdue
0
The "stableSort" property does have a performance cost. Therefore, it is set to "false" by default and should be set to "true" only when needed.
1 2 3 4 5 6 | // This file locates: "Scripts/Lesson/C1Mvc/CVStableSort.js". c1.documentReady(function () { var theGrid = wijmo.Control.getControl( '#theGrid' ); var view = theGrid.collectionView; view.useStableSort = true ; }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | using System.Web.Mvc; using System.Linq; namespace LearnMvcClient.Controllers { public partial class C1MvcController : Controller { // GET: CVStableSort public ActionResult CVStableSort() { var data = Models.FlexGridData.GetSales(200).OrderBy(s => s.Country); return View(data); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | @model IEnumerable< FlexGridData.Sale > < h1 > @Html .Raw(Resources.C1Mvc.CVStableSort_Title) </ h1 > < p > @Html .Raw(Resources.C1Mvc.CVStableSort_Text1) </ p > < p > @Html .Raw(Resources.C1Mvc.CVStableSort_Text2) </ p > @ (Html.C1().FlexGrid().Id( "theGrid" ).Height(250) .Bind(b=>b.Bind(Model).DisableServerRead( true )) ) < p > @Html .Raw(Resources.C1Mvc.CVStableSort_Text3) </ p > |