In most cases line items on documents are sorted by Line No.
However you may want to change the sort for your screen views and your form templates.
On any document screen you can change the sort by clicking the List Layout Edit gear icon. Then click the other tab, change your sort column as required and click Save. This setting is stored by browser and documents type.
Similarly, you can set a completely different item sort within form templates. After Saving the sort, make sure to also click Save for the form template as a whole. This setting is set per form template.