Sorting a view by ID

April 24, 2011 Posted by Anders Asp

Have you ever tried to sort a view after the ID only to realise that it’s actually sorted alphabetically?

Sort by ID - Before

Sort by ID - Before

Now, you could use properties such as Created date to do a proper sort, but wouldn’t it be better if we could make the sorting of ID numerical instead?

That is actually possible and to do so you would have to start with exporting your MP in which the view is stored. Then open the MP and locate your view within the XML code, and take a look at the <columns> section. In the columns section, you should have a line that looks like this:

<mux:Column Name=”Id” DisplayMemberBinding=”{Binding Path=Id}” Width=”100″ DisplayName=”Id.9108474bffe74ec98f268d6e5f7b948b” Property=”Id” DataType=”s:String” />

Now to make the sorting to work ‘correctly’, all we need to do is changing the Property from “Id” to “Id$ReturnValueAsBigInt$”, like this:

<mux:Column Name=”Id” DisplayMemberBinding=”{Binding Path=Id}” Width=”100″ DisplayName=”Id.9108474bffe74ec98f268d6e5f7b948b” Property=”Id$ReturnValueAsBigInt$” DataType=”s:Int32″ />

After you’ve done this, save your MP, re-import it and restart your console. Now the sorting of ID in that view should be done in a numerical way instead of an alphabetic.

Sort by ID - After

Sort by ID - After

Leave a Reply

Your email address will not be published. Required fields are marked *

*