@@ -1016,7 +1016,7 @@ internal async Task OnSort(EventArgs args, RadzenDataGridColumn<TItem> column)
10161016
10171017 var property = column . GetSortProperty ( ) ;
10181018
1019- SetColumnSortOrder ( column ) ;
1019+ SetNextColumnSortOrder ( column ) ;
10201020 await Sort . InvokeAsync ( new DataGridColumnSortEventArgs < TItem > ( ) { Column = column , SortOrder = column . GetSortOrder ( ) } ) ;
10211021 SaveSettings ( ) ;
10221022
@@ -3153,7 +3153,20 @@ internal bool IsOData()
31533153
31543154 internal List < SortDescriptor > sorts = new List < SortDescriptor > ( ) ;
31553155
3156- internal void SetColumnSortOrder ( RadzenDataGridColumn < TItem > column )
3156+ internal void SetNextColumnSortOrder ( RadzenDataGridColumn < TItem > column )
3157+ {
3158+ var sequence = column . SortOrderSequence ;
3159+
3160+ var pos = Array . IndexOf ( sequence , column . GetSortOrder ( ) ) ;
3161+
3162+ var nextSortOrder = pos == - 1 || pos + 1 >= sequence . Length
3163+ ? sequence . FirstOrDefault ( )
3164+ : sequence [ pos + 1 ] ;
3165+
3166+ SetColumnSortOrder ( column , nextSortOrder ) ;
3167+ }
3168+
3169+ private void SetColumnSortOrder ( RadzenDataGridColumn < TItem > column , SortOrder ? sortOrder )
31573170 {
31583171 if ( ! AllowMultiColumnSorting )
31593172 {
@@ -3165,35 +3178,33 @@ internal void SetColumnSortOrder(RadzenDataGridColumn<TItem> column)
31653178 }
31663179
31673180 var descriptor = sorts . Where ( d => d . Property == column ? . GetSortProperty ( ) ) . FirstOrDefault ( ) ;
3168- if ( descriptor == null )
3169- {
3170- descriptor = new SortDescriptor ( ) { Property = column . GetSortProperty ( ) } ;
3171- }
31723181
3173- if ( column . GetSortOrder ( ) == null )
3174- {
3175- column . SetSortOrderInternal ( SortOrder . Ascending ) ;
3176- descriptor . SortOrder = SortOrder . Ascending ;
3177- }
3178- else if ( column . GetSortOrder ( ) == SortOrder . Ascending )
3179- {
3180- column . SetSortOrderInternal ( SortOrder . Descending ) ;
3181- descriptor . SortOrder = SortOrder . Descending ;
3182- }
3183- else if ( column . GetSortOrder ( ) == SortOrder . Descending )
3182+ column . SetSortOrderInternal ( sortOrder ) ;
3183+
3184+ if ( ! sortOrder . HasValue )
31843185 {
3185- column . SetSortOrderInternal ( null ) ;
3186- if ( sorts . Where ( d => d . Property == column ? . GetSortProperty ( ) ) . Any ( ) )
3186+ if ( descriptor != null )
31873187 {
31883188 sorts . Remove ( descriptor ) ;
31893189 }
3190- descriptor = null ;
3190+
3191+ return ;
31913192 }
31923193
3193- if ( descriptor != null && ! sorts . Where ( d => d . Property == column ? . GetSortProperty ( ) ) . Any ( ) )
3194+ if ( descriptor == null )
31943195 {
3196+ descriptor = new SortDescriptor ( )
3197+ {
3198+ Property = column . GetSortProperty ( ) ,
3199+ SortOrder = sortOrder ,
3200+ } ;
3201+
31953202 sorts . Add ( descriptor ) ;
3203+
3204+ return ;
31963205 }
3206+
3207+ descriptor . SortOrder = sortOrder ;
31973208 }
31983209
31993210 void GroupsCollectionChanged ( object sender , NotifyCollectionChangedEventArgs args )
@@ -3377,7 +3388,7 @@ public void OrderBy(string property)
33773388
33783389 if ( column != null )
33793390 {
3380- SetColumnSortOrder ( column ) ;
3391+ SetColumnSortOrder ( column , SortOrder . Ascending ) ;
33813392 Sort . InvokeAsync ( new DataGridColumnSortEventArgs < TItem > ( ) { Column = column , SortOrder = column . GetSortOrder ( ) } ) ;
33823393 SaveSettings ( ) ;
33833394 }
@@ -3403,9 +3414,7 @@ public void OrderByDescending(string property)
34033414
34043415 if ( column != null )
34053416 {
3406- column . SetSortOrderInternal ( SortOrder . Ascending ) ;
3407- SetColumnSortOrder ( column ) ;
3408-
3417+ SetColumnSortOrder ( column , SortOrder . Descending ) ;
34093418 Sort . InvokeAsync ( new DataGridColumnSortEventArgs < TItem > ( ) { Column = column , SortOrder = column . GetSortOrder ( ) } ) ;
34103419 SaveSettings ( ) ;
34113420 }
0 commit comments