You can programmatically sort rows or columns or a range of cells. You can specify the order of sorting and the comparison method for sorting. You can allow your users to sort rows automatically simply by clicking on the column header. Use methods at the sheet level to perform these kinds of sorting:
For more information about sorting, refer to Managing Sorting of Rows of User Data.