Enable the 'Auto-sort' items under Char Config -> Control settings -> Character

Once that's checked off, goto your retainer and dump your entire inventory into the retainer, then take out the items you need. Your inventory is now autosorted. Takes about 3 minutes. Your potions/meals will be on page 3, materials on page 4, and everything else on pages 1/2.