I am looking to add a sort button to my data that is displayed on my screen. At the monet i have my repo set up as shown.
@Repository
public interface PlayerRepository extends JpaRepository<Player, Long> {
Player findAllById(Long id);
List<Player> findByOrderByPlayerNameAsc();
}
And in my controller class i have it as such:
@GetMapping("/player")
public String displayPlayer(Model model) {
model.addAttribute("player", service.findAll());
return "/player";
}
I want to be able to create a new method and have it as such so that when i click a button on the html of my application it calls this method and sorts the data. At the moment on loading of the screen it displays all data unfiltered, if i change it to use the "findByOrderByPlayerNameAsc" one it automatically filters upon loading. But i would like this to only happen when a button is clicked.
public String displayPlayerFilteredByName(Model model) {
model.addAttribute("player", service.findByOrderByPlayerNameAsc());
return "/player";
}
Is this possible using simply java and html? Or is there an alternative using JS?