All the C# code examples presented on this page can be found in the related demo function of MS Visual Studio project FinaquantProtosStarter which can be downloaded at the
product page of the free .NET library finaquant® protos.
Sorting rows of tables after some fields may be required for certain table calculations. The table function
SortRows() in
finaquant® protos (free .net library) can be used for sorting tables:
// Sort table after given fields and sort options (ASC/DESC).
// Sort after all fields in order (ASC) if SortStr is null or empty string ""
// Tbl: Input table
// SortStr: Comma separated field names and sort option, like "field1 ASC, field2 DESC"
// Returns: Sorted table
public static MatrixTable SortRows(MatrixTable Tbl, string SortStr = null) |
// Sort table after given fields and sort options (ASC/DESC).
// Sort after all fields in order (ASC) if SortStr is null or empty string ""
// Tbl: Input table
// SortStr: Comma separated field names and sort option, like "field1 ASC, field2 DESC"
// Returns: Sorted table
public static MatrixTable SortRows(MatrixTable Tbl, string SortStr = null)
You may find some examples with the CostTable below.
Shuffle rows of CostTable before sorting
// shuffle rows
CostTable = MatrixTable.ShuffleRows(CostTable, 5000);
// view table
MatrixTable.View_MatrixTable(CostTable, "Shuffled CostTable"); |
// shuffle rows
CostTable = MatrixTable.ShuffleRows(CostTable, 5000);
// view table
MatrixTable.View_MatrixTable(CostTable, "Shuffled CostTable");
1) Sort CostTable after fields category, product (descending order) and date
SortStr = "category, product DESC, date";
MatrixTable SortedTbl = MatrixTable.SortRows(CostTable, SortStr);
// view table
MatrixTable.View_MatrixTable(SortedTbl, "Sorted CostTable, SortStr = \"category, product DESC, date\""); |
SortStr = "category, product DESC, date";
MatrixTable SortedTbl = MatrixTable.SortRows(CostTable, SortStr);
// view table
MatrixTable.View_MatrixTable(SortedTbl, "Sorted CostTable, SortStr = \"category, product DESC, date\"");
2) Sort CostTable after all fields (from category to costs) in ascending order
SortedTbl = MatrixTable.SortRows(CostTable);
MatrixTable.View_MatrixTable(SortedTbl, "Sorted CostTable, SortStr = null"); |
SortedTbl = MatrixTable.SortRows(CostTable);
MatrixTable.View_MatrixTable(SortedTbl, "Sorted CostTable, SortStr = null");
3) Sort CostTable after fields date, brand (descending order) and costs
SortStr = "date, brand DESC, costs";
SortedTbl = MatrixTable.SortRows(CostTable, SortStr);
MatrixTable.View_MatrixTable(SortedTbl, "Sorted CostTable, SortStr = \"date, brand DESC, costs\""); |
SortStr = "date, brand DESC, costs";
SortedTbl = MatrixTable.SortRows(CostTable, SortStr);
MatrixTable.View_MatrixTable(SortedTbl, "Sorted CostTable, SortStr = \"date, brand DESC, costs\"");
Copyright secured by Digiprove © 2013 Tunc Ali Kütükcüoglu
2 in finaquant® protos (free .net library) can be used for sorting tables: // Sort table after given fields and sort" data-image="http://software.tuncalik.com/wp-content/uploads/2013/01/SortingTables_ShuffledCostTable-300x229.png" data-button="">