Advertisement
jkennerly

Telerik Letter-based sort with "less than" filter.

Aug 13th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. //////////////////////////////////////////////////////////////////////////////
  2. // Possible sort algorithm of Telerik's letter-based "Less Than" grid filter.
  3. //
  4. // Note:  to run this example use a C# Console app or download LINQPad
  5. //        from http://www.linqpad.net/
  6. //////////////////////////////////////////////////////////////////////////////
  7.  
  8. // List<string> input = new List<string> {  "someprovider01", "someprovider02", "someprovider00", "404", "1000" };
  9. List<string> input = new List<string> {  "100", "200", "300", "400", "500", "600", "1000" };
  10.  
  11. // Letter based sort first.
  12. var sortedList = from i in input
  13.          orderby i ascending
  14.          select i;   
  15.                  
  16. sortedList.Dump(); // OUTPUT    "100", "1000", "200", "300", "400", "500", "1000"
  17.  
  18. // Create an index on the sorted list.
  19. var indexedList = (from i in sortedList.Select((number, index) => new { index, number })
  20.            select i).ToDictionary(item => item.index, item => item.number);          
  21.  
  22. indexedList.Dump(); // OUTPUT   0 : "100", 1 : "1000", 2 : "200", 3 : "300", 4 : "400", 5 : "500", 6 : "1000
  23.  
  24. // Get last postion in regards to "less than" 500
  25. int lastOrdinal = (from i in indexedList
  26.            where Convert.ToInt32(i.Value) == 500
  27.            select i.Key).Single();
  28.  
  29. lastOrdinal.Dump(); // OUTPUT   5
  30.  
  31.                  
  32. var lessThan500 = from i in indexedList
  33.           where i.Key < lastOrdinal
  34.           select i.Value;
  35.  
  36. lessThan500.Dump(); // OUTPUT:  100, 1000, 200, 300, 400
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement