Allow the user to change the way results are shown?

Can anyone tell me how to set up a page so that the user can choose whether to display the results as a grid format or as rows?

What I’m looking to do is shown here:

The part that lets the user change how results are displayed.

Can anyone point me in the direction to get this working please?

Thanks for any help in advance.

Worked it out, thanks

At first glance it looks like a css switch, is this what you did in the end?