Before you test it with selenium , you need to do a small thing. Save the table values (which appear after sorting) to stringor array.
Now sort using selenium and write the new list as
string new_list= selenium.gettable("xpath");
Now compare both values and see if they are the same or not.
source
share