@@ -1121,12 +1121,51 @@ private bool VerifyDuplicateKeys()
11211121
11221122 public ISolutionItem SolutionItem => ( ( ISolutionItem ? ) perDbSolutionItem ?? perEntitySolutionItem ) ! ;
11231123
1124- public void SortElements ( )
1124+ public void SortElements ( int sortByCellIndex , bool ascending )
11251125 {
11261126 using var bulk = HistoryHandler . WithinBulk ( "Sort loot" ) ;
11271127 foreach ( var group in Loots )
11281128 {
1129- var copy = group . LootItems . OrderBy ( x => x . GroupId . Value )
1129+ var source = group . LootItems ;
1130+ if ( source . Count == 0 )
1131+ continue ;
1132+
1133+ var firstRow = source [ 0 ] ;
1134+ IOrderedEnumerable < LootItemViewModel > ordered ;
1135+ if ( firstRow . CellsList [ sortByCellIndex ] is LootItemParameterCellLong )
1136+ {
1137+ if ( ascending )
1138+ ordered = source . OrderBy ( x => ( ( LootItemParameterCellLong ) x . CellsList [ sortByCellIndex ] ) . Value ) ;
1139+ else
1140+ ordered = source . OrderByDescending ( x => ( ( LootItemParameterCellLong ) x . CellsList [ sortByCellIndex ] ) . Value ) ;
1141+ }
1142+ else if ( firstRow . CellsList [ sortByCellIndex ] is ItemNameStringCell )
1143+ {
1144+ if ( ascending )
1145+ ordered = source . OrderBy ( x => ( ( ItemNameStringCell ) x . CellsList [ sortByCellIndex ] ) . StringValue ) ;
1146+ else
1147+ ordered = source . OrderByDescending ( x => ( ( ItemNameStringCell ) x . CellsList [ sortByCellIndex ] ) . StringValue ) ;
1148+ }
1149+ else if ( firstRow . CellsList [ sortByCellIndex ] is LootItemParameterCell < float > )
1150+ {
1151+ if ( ascending )
1152+ ordered = source . OrderBy ( x => ( ( LootItemParameterCell < float > ) x . CellsList [ sortByCellIndex ] ) . Value ) ;
1153+ else
1154+ ordered = source . OrderByDescending ( x => ( ( LootItemParameterCell < float > ) x . CellsList [ sortByCellIndex ] ) . Value ) ;
1155+ }
1156+ else if ( firstRow . CellsList [ sortByCellIndex ] is ActionCell )
1157+ {
1158+ continue ;
1159+ }
1160+ else
1161+ {
1162+ messageBoxService . SimpleDialog ( "Error" , "Non critical error - can't sort by this column" ,
1163+ "This is an internal error, please report it. Can't sort the loot, because " +
1164+ LootColumns [ sortByCellIndex ] . Header + " is not sortable" ) ;
1165+ continue ;
1166+ }
1167+
1168+ var copy = ordered
11301169 . ThenBy ( x => x . ItemOrCurrencyId . Value )
11311170 . ToList ( ) ;
11321171 group . LootItems . RemoveAll ( ) ;
0 commit comments