Bug: UDTableColumn -DefaultSortColumn not working

Product: PowerShell Universal
Version: 1.5.16

As described in the title the DefaultSortColumn parameter does not work

In addition I realized that when sorting for a column instead of switching let’s say from A-Z and then Z-A, there’s a third sorting that is performed which is non-sense. It’s either A-Z nor Z-A… When you then click the column once more, it starts again with sorting correctly:
A-Z => Z-A => nonsense (unsorted), … etc.

=> This last issue is also noticeable on 1.6.x


Are you using -LoadData or the -Data parameter?

As for the unsorted state, we can disable that via the library we are using. It seems they off a disableSortRemove option to prevent this from happening: API Reference: useSortBy | React Table | TanStack

Hey @adam

I’m using -Data as shown in your docs:

Why, shall I use -LoadData? And what’s the difference in that case?

With regards to your final statement:
Do I understand it correctly that the library offers a function but you’ll need to implement it into PSU?
If that’s the case, first of all thanks a lot for doing that! I think it would absolutely make sense. Additionally the MultiSort would also make a lot of sense to me… Like the sorting function in Excel. where you basically specify the sortBy column order:
For example: First = Company, Second = Last Name

… just in case you want to make UDTable even more “pro” :smiley:

THANKS A LOT again for all your efforts and considerations of our user feedbacks! Top!

Have a very good weekend!


When you use -LoadData, is for server-side data loading and we process things a bit differently in that case. I just wanted to understand how to approach the issue.

As for the sorting, we do need to implement the functionality in PSU that the library provides. I think the library offers multi-sort as well so I’ll open an issue for that too to see if we can get that going for you.


Thank you soooo much! Really much appreciated! :smiley: :+1:

Enjoy your weekend!

Dear @adam

Just wanted to let you know that the -DefaultSortColumn is “gone” again in the latest nightly.
Would it be possible to fix that in one of your next releases?


It looks like this broken due to the introduction of -DefaultSortDirection. The default value is unsorted. If you set the default sort direction in one way, it works.

    $Data = @(
        @{Dessert = 'Frozen yoghurt'; Calories = 1; Fat = 6.0; Carbs = 24; Protein = 6.0}
        @{Dessert = 'Ice cream sandwich'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 2.0}
        @{Dessert = 'Eclair'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 9.0}
        @{Dessert = 'Cupcake'; Calories = 159; Fat = 6.0; Carbs = 24; Protein = 1.0}
        @{Dessert = 'Gingerbread'; Calories = 200; Fat = 6.0; Carbs = 24; Protein = 4.0}

    $Columns = @(
        New-UDTableColumn -Property Dessert -Title Dessert -Render { 
            New-UDButton -Id "btn$($EventData.Dessert)" -Text "Click for Dessert!" -OnClick { Show-UDToast -Message $EventData.Dessert } 
        New-UDTableColumn -Property Calories -Title Calories 
        New-UDTableColumn -Property Fat -Title Fat 
        New-UDTableColumn -Property Carbs -Title Carbs 
        New-UDTableColumn -Property Protein -Title Protein  -DefaultSortColumn

    New-UDTable -Data $Data -Columns $Columns -Sort -Export -DefaultSortDirection Ascending

Briliant, thanks! It works as you described.
However just keep in mind that this implementation on the other hand breaks 1.5.x :wink:

So I don’t know if you want to consider it somehow in your docs in case 1.5.x will be maintenaned for a while after the release of 1.6…