Hi Irfan,
Have you checked the learning course here?
It shows the steps for you to use the dynamic sort manually.
Alternatively, you have the option to create the sorting automatically.

This will work if you use simple aggregate (without GroupBy).
But if you use Group By, you have to rename your HeaderCell to use your GroupBy's Name
Example above will be RecordName for the SortAttribute, in the logic itself, you have to refactor "RecordName" to "Record.RecordName" for the aggregate to work.

E.g.,
If SortBy = "RecordName"
Then SortBy = "Record.RecordName"
For static sorting, you just have to add the attribute under Sorting in the aggregate.

If you want to use dropdown list to sort your listing, you have to define that as well,
DropdownOnChange -> If(SelectedId = Entities.SortBy.Favourite), SortBy = "Table.IsFavourite", ...)
The training really helps you with the basics. Hope it helps.
Kenny