What order should you use for adding items to inventory systems

if you have a grid-like inventory system, independent of the default inventory system, what order should you add an item
because i’ve seen people using containers to sort whatever items they have into categories, like this framework/tutorial, and i’m trying to make my own without completely copying it, but i think it’s container system is moreso to seperate hotbar slots and normal inventory slots, while i just want to sort the items but still use the container system
should i add the item to the inventory data, and THEN sort it, or should i just insert the item into the correct position and displace everything else?

You’re asking for an opinion, so this is my opinion:

Keep it simple, add the item to your inventory data first, then sort it into the container.
Inventory data is a raw list of items, sorting just updates the container or UI.
Avoid trying to shove it into the grid and push everything else manually, it gets messy.
Only insert directly if you need strict slot by slot placement, otherwise add then sort.