When you are using inline HTML, sorting function will use the HTML value of the cell, and will try to sort the HTML strings, which may lead to the unwanted result.
You can try to use link column type instead. As resutl grid will be sorted by link’s text.