I use bootstrap, so is easy to add classes that respond to the page width. No need for BE or php functions. Only edit the view template adding your own classes to the item element like: col-12 col-md-6 col-lg-4 will. This will render a single column for small screens, 2 columns for medium size, and 3 columns for desktop. You should be able to do something like that with js using your own classes https://getbootstrap.com/docs/5.0/layout/grid/#mix-and-match